﻿

/*------------------------------------------------------------------------------------------------------\
|                                          页面控制类 Sail.pageConsole                                  |
|-------------------------------------------------------------------------------------------------------|
|作者：于俊杰                                                                                           |
|时间：2008-02-27 创建并注释                                                                            |
|说明：                                                                                                 |
|                                                                                                       |
|-------------------------------------------------------------------------------------------------------|
|             【对象】                    |                          【说明】                           |
|-------------------------------------------------------------------------------------------------------|
| Sail.constructor                        | 对象：                                                      |
|                                         |                                                             |
|-------------------------------------------------------------------------------------------------------|
|                                       Copyright (c) 2007 YuJunJie                                     |
\------------------------------------------------------------------------------------------------------*/

Sail.pageConsole = function(){
    this.el       = [];
    this.widgets  = [];
    this.mainDiv  = null;
    this.sRequest = null;
    
    this.bindRelation = [];

    this.serviceIP = "";
    this.getUrlParameter = [];
    this.getUrl          = this.serviceIP+"/OSVCSolutio/DataMap?funcname=listbyqry";
    this.postUrl         = "";
        
    this.pauseLoadData   = false;
    
    this.SearchContainer = null;
    this.searchArrange   = [];

    this.dataContainer = [];
    this.dataArrange = [];
    
    this.serviceUrl_List      = this.serviceIP+"/yyPrj/DataMap?funcname=listdefault";
    this.serviceUrl_Save      = this.serviceIP+"/yyPrj/DataMap?funcname=save";
    this.serviceUrl_ListByQry = this.serviceIP+"/yyPrj/DataMap?funcname=listbyqry";
    this.serviceUrl_Detail    = this.serviceIP+"/yyPrj/DataMap?funcname=detail";
    this.serviceUrl_Audit     = this.serviceIP+"/yyPrj/DataMap?funcname=audit";
    this.serviceUrl_Del       = this.serviceIP+"/yyPrj/DataMap?funcname=delete";
    this.serviceUrl_Update    = this.serviceIP+"/yyPrj/DataMap?funcname=update";
    
    this.showJsonBeforePost = false;
    
    
    this.runMode = "";
    
    this.replaceChar = "__";
    this.widgetIDIndex = 1000;
    
    this.naviRequest = "/cdmes/DataDict?funcname=basicdata";
    //this.naviRequest = "dataRoot.txt";
    
    this.loginInfo = {
        navi:"",            //导航条
        opername:"",        //登录人姓名
        opertype:"",        //登录人类别
        operorgid:"",       //登录人部门ID
        operorgname:"",     //登录人部门名称
        factoryName:"",     //登录人工厂名称
        factoryID:"",       //登录人工厂ID
        opercode:"",        //登录人编码
        operator:"",        //登录人ID
        operfun:""
    };


    
    this.saveFlag  = false;
    this.tabindex  = 1;
}

Sail.pageConsole.prototype = {
    
    formatNum : function(value,digit){
        if(digit==undefined)
            return Math.round(value*100)/100;
        else{
            if(digit==0){
                return Math.round(value);
            }else{
                var tmp = Math.pow(10,digit);
                return Math.round(value*tmp)/tmp;
            }
        }
    },
    getTabindex: function(){
        return this.tabindex++;
    },
    //===========================================================================================
    //方法： 一组获得组件的方法 
    //说明： 
    //       getWidgetByID          根据组件ID 获得组件
    //       getWidgetByTitle       根据组件标题 获得组件
    //       getWidgetByName        根据组件名称 获得组件
    //       getWidgetByProperty    根据组件属性 获得组件
    //       getEl                  根据ID 获得组件实体对象
    //===========================================================================================
    getWidgetIndexByID : function(_id){
        for(var i=0,len=this.el.length;i<len;i++){ if(this.el[i].id==_id) return i; } return -1;
    },
    getWidgetIndexByProperty : function(p,v){
        var a = new Array();
        for(var i=0,len=this.el.length;i<len;i++){ if(this.el[i][p]==v) a.push(i);}
        return (a.length==1)?a[0]:((a.length>1)?a:-1);
    },
    getWidgetIndexByTitle : function(v){ return this.getWidgetIndexByProperty("title",v); },
    getWidgetIndexByName  : function(v){ return this.getWidgetIndexByProperty("name",v);  },

    
    getWidgetByID : function(_id){
        for(var i=0,len=this.el.length;i<len;i++){ if(this.el[i].id==_id) return this.el[i]; } return null;
    },
    getWidgetByProperty : function(p,v){
        var a = new Array();
        for(var i=0,len=this.el.length;i<len;i++){ if(this.el[i][p]==v) a.push(this.el[i]);}
        return (a.length==1)?a[0]:((a.length>1)?a:null);
    },
    getWidgetByTitle : function(v){ return this.getWidgetByProperty("title",v); },
    getWidgetByName  : function(v){ return this.getWidgetByProperty("name",v);  },
    getEl : function(_id){
        for(var i=0,len=this.el.length;i<len;i++){ if(this.el[i].id==_id) return this.el[i].el; } return null;
    },
    getWidgetDefineByProperty : function(p,v){
        var a = new Array();
        for(var i=0,len=this.widgets.length;i<len;i++){ if(this.widgets[i][p]==v) a.push(this.widgets[i]);}
        return (a.length==1)?a[0]:((a.length>1)?a:null);
    },
    
    showMessage : function(_title,_message,type){
        var iconType = (type=="warning")?Ext.MessageBox.WARNING:((type=="info")?Ext.MessageBox.INFO:((type=="error")?Ext.MessageBox.ERROR:Ext.MessageBox.QUESTION));
        Ext.MessageBox.show({
            title: _title,
            msg: _message,
            buttons: Ext.MessageBox.OK,
            icon: iconType
        });
    },
    
    removeEl :function(index){
        var _id    = this.el[index].id;
        var _name  = this.el[index].name;
        var _title = this.el[index].title;
        
        var tmpObj = {};
        for(var p in sys_findedWidget){
            if(p!=_id && p!=_name && p!=_title)
                tmpObj[p] = sys_findedWidget[p];
        }
        
        sys_findedWidget={};
        Ext.apply(sys_findedWidget,tmpObj);
        tmpObj = null;
        
        
        //-----------------------------------------------------------
        //-----------------------------------------------------------
        //for(var i=0;
        
        //-----------------------------------------------------------
        //-----------------------------------------------------------
        this.el.splice(index,1);
    },
    
    
    getDateByString : function(_date){
        var infos = _date.split('-');
        infos[0] = parseInt(infos[0],10);
        infos[1] = parseInt(infos[1],10)-1;
        infos[2] = parseInt(infos[2],10);
        
        return new Date(infos[0],infos[1],infos[2]);
    },
    //===========================================================================================
    //方法：
    //说明：
    //===========================================================================================
    /*getUser : function(){
        return this.loginInfo.operator;
    },*/
    haveOperFun : function(funName,tabName){
    	return;
        if(this.loginInfo.operfun=="" || this.loginInfo.operfun==undefined) 
            return false;
            
        var list = ","+this.loginInfo.operfun+",";
        var findFun = ","+tabName+"_"+funName+","

        if(list.indexOf(findFun)==-1){
            findFun = ","+funName+",";
            return (list.indexOf(findFun)==-1)?false:true;
        }else{
            return true;
        }
    },
    getOperfun : function(){
        return this.loginInfo.operfun;
    },
    
    getFactoryName : function(){
        //return this.loginInfo.operorgname;
        return this.loginInfo.factoryName;
    },
    getFactoryID : function(){
        //return this.loginInfo.operorgid;
        return this.loginInfo.factoryID;
    },
    getOpername : function(){
        return this.loginInfo.opername;
    },
    getOpertype : function(){
        return this.loginInfo.opertype;
    },
    getOperorgid : function(){
        return this.loginInfo.operorgid;
    },
    getOperorgname : function(){
        return this.loginInfo.operorgname;
    },
    getOpercode : function(){
        return this.loginInfo.opercode;
    },
    getLogin: function(){
        return this.loginInfo;
    },
    
    getUser : function(){
        //debugger;
        return this.loginInfo.operator;

        if(Sail.data.business.dataset){
            if(Sail.data.business.dataset.others){
                if(Sail.data.business.dataset.others.operator){
                    return Sail.data.business.dataset.others.operator;
                }
            }
        }
        return '';
    },

    //===========================================================================================
    //方法： initWidget 
    //说明： 构造页面组件对象
    //===========================================================================================
    initWidget : function(){
        var h = this.mainDiv.offsetHeight,_flag=false;
        for(var i=0,len=this.widgets.length;i<len;i++){
            var _h = this.widgets[i].top+this.widgets[i].height;
            if(_h>h) {_flag=true;break;}
        }

        for(var i=0,len=this.widgets.length;i<len;i++){
            var _wDefine       = this.widgets[i];
            _wDefine.add2Win   = this.mainDiv;
            _wDefine.add2Group = this.el;
            _wDefine.scrollflag = _flag;
            
            var newWidget = eval("new Sail.widget."+_wDefine.type+"();");
            newWidget.create(_wDefine);
        }
    },
    adjustWidget : function(){
        for(var i=0;i<this.dataContainer.length;i++){
            var nowObj = this.dataContainer[i];
            for(var index=0;index<nowObj.subWidgets.length;index++){
                var w = nowObj.subWidgets[index];
                if(w.brother){
                    var wDefines = [];
                    wDefines.push(w); 
                    if(w.brother instanceof Array){
                        wDefines = wDefines.concat(w.brother);
                    }else{
                        wDefines.push(w.brother);
                    }
                    
                    var totalTitleWidth = 0;
                    var wObjs = [];
                    for(var k=0;k<wDefines.length;k++){
                        if(wDefines[k].id)
                            wObjs[k] = $(wDefines[k].id);
                        else if(wDefines[k].name)
                            wObjs[k] = $(wDefines[k].name);
                        else 
                            wObjs[k] = $(wDefines[k].title);
                            
                        totalTitleWidth+=wObjs[k].titleWidth+4;
                    }

                    var totalWidth = wObjs[wObjs.length-1].left+wObjs[wObjs.length-1].width-wObjs[0].left;
                    boxWidth = (totalWidth - totalTitleWidth)/wObjs.length;
                    for(var k = 0;k<wObjs.length;k++){
                        wObjs[k].setBoxWidth(boxWidth);
                        if(k>0)
                            wObjs[k].setLeft(wObjs[k-1].left+wObjs[k-1].width+1)
                    }
                }
            }
        }
        
        if(this.isList()){
            this.addNavi();
        }
        
        this.adjustButton();
    },
    
    adjustButton : function(){
        if(this.SearchContainer!=undefined){
            this.adjustFormButton(this.SearchContainer);
        }
        for(var i=0;i<this.dataContainer.length;i++){
            this.adjustFormButton(this.dataContainer[i],this.dataArrange[i]);
        }
    },
    
    adjustFormButton : function(container,arrange){
        if(arrange!=undefined){
            for(var i=0;i<arrange.length;i++){
                if(arrange[i].align=='left'){
                    var left = 10;
                    for(var j=0;j<arrange[i].sub.length;j++){
                        var w = $(arrange[i].sub[j]);
                        w.setLeft(left);
                        var width = w.el.el.getBox().width;
                        left+=width+10;
                    }
                }
            }
        }else{
            var left = 10;
            for(var i=0;i<container.subWidgets.length;i++){
                if(container.subWidgets[i].type=='ext.button'){
                    var w = $(container.subWidgets[i].id);
                    w.setLeft(left);
                    var width = w.el.el.getBox().width;
                    left+=width+10;
                }
            }
        }
    },
    
    addNavi : function(){
        var _widgets = Sail.data.widgets;
        for(var i=0;i<_widgets.length;i++){
            var _widget = $(_widgets[i].id);
            
            _widget.setTop(_widget.top+20);
        }
        
        var o = {        
            "id"             : "ext.label.navi",
            "name"           : "label.navi",
            "type"           : "ext.label",
            "title"          : this.loginInfo.navi,
            "left"           : 2,
            "top"            : 0,
            "width"          : 680,
            "height"         : 22,
            "canbeContainer" : false,
            "fatherObjID"    : "design-div-0",
            "ownerTab"       : -1,
            "useIcon"        : true,
            "add2Win"        : this.mainDiv,
            "add2Group"      : this.el
        }
        
        var newWidget = eval("new Sail.widget."+o.type+"();");
        newWidget.create(o);
    },

    createWidget : function(config){
        if(!config.add2Win)     config.add2Win   = this.mainDiv;
        if(!config.add2Group)   config.add2Group = this.el;
        
        var newWidget = eval("new Sail.widget."+config.type+"();");
        newWidget.create(config);
    },
    

    //===========================================================================================
    //方法： bindWidget
    //说明： 新增一个组件与数据绑定关系
    //===========================================================================================
    bindWidget : function(r){
        if(typeof r == 'object'){
            if(r instanceof Array){
                for(var i=0;i<r.length;i++)
                    this.bindRelation.push(r[i]);
            }else{
                this.bindRelation.push(r);
            }
        }
    },

    //===========================================================================================
    //方法： changeWidgets
    //说明： 在构造之前变更组件的属性定义
    //===========================================================================================
    changeWidget : function(r){
        var ws = [];
        if(typeof r == 'object'){
            if(r instanceof Array)
                ws = ws.concat(r);
            else
                ws.push(r);
            this.changeWidget2SDW(ws);
        }
    },
    changeWidget2SDW : function(ws){
        for(var i=0,len=ws.length;i<len;i++){
            var v = ws[i].widget;
            var o = this.findWidgetBy(Sail.data.widgets,v);
            if(o!=null){
                Ext.apply(o,ws[i].config);
            }
        }
    },
    findWidgetBy : function(ws,t){
        for(var i=0;i<ws.length;i++){
            if(ws[i].title==t || ws[i].id==t || ws[i].name==t) 
                return ws[i];
            else{
                if(ws[i].subWidgets&&ws[i].subWidgets.length>0){
                    var o = this.findWidgetBy(ws[i].subWidgets,t);
                    if(o!=null) return o;
                }
            }
        }
        return null;
    },
    
    //===========================================================================================
    //方法：  
    //说明： 
    //===========================================================================================
    postData : function(_url,postData,successInfo,errorInfo){
        if(_url=="") {
            Ext.Msg.alert("信息","没有找到url！");
            return;
        }
        this.showLoadMask('正在处理数据，请等待........');
        
        var theObj = this;
        Ext.Ajax.request({
            url: _url,method: 'POST',params: postData,
            success: function(action) {
                theObj.hideLoadMask();
                //debugger;
                var getResponse = eval("("+action.responseText+")"); 
                var flag = getResponse.dataset.response.success;
                
                if(typeof successInfo =="function") {
                    successInfo.call(this,flag,getResponse);
                }else{
                    Ext.Msg.alert('提示：', successInfo); return true;
                }
            },
            failure: function(action) {
                theObj.hideLoadMask();
                var _status = action.status; 

                if(typeof errorInfo =="function") {
                    errorInfo.call(this,false,_status);
                }else{
                    Ext.Msg.alert('提示：', '获取数据失败！'); return false;
                }
                
                //Ext.Msg.alert('提示：', '获取数据失败！'); return false;
                
            }
        });
    },
    deleteRecord : function(_url,postData){
        this.postData(_url,postData,"删除数据成功！","删除数据失败！");
    },
    
    //===========================================================================================
    //方法：  loadData & afterLoadData
    //说明： 
    //===========================================================================================
    loadData : function(){
        if(this.getUrl=="") {
            //alert("错误：\n\n加载数据时，this.getUrl 为空！");
            this.loadOver();                //
            //try{
                addEvent2Widget();
            //}catch(e){
              //  alert("错误：\n\n为组件绑定事件时发生！ 发生在addEvent2Widget方法中！\n\n"+e.message);
            //}
            return;
        }
        //debugger;
        //------------------------------------------------------------------------
        //新增模式下的处理
        //------------------------------------------------------------------------
        if(this.isAdd()){                   //如果是新增，则不需要 loaddata
            this.afterLoadData();           //执行加载数据完成后方法

            this.beforeCreateWidgets();     //构造页面组件前，可能的在这里处理数据结构
            this.createWidgets();           //构造组件

            this.bindData();                //绑定数据到组件
            return;
        }
        //------------------------------------------------------------------------
        //修改模式下的处理
        //------------------------------------------------------------------------
        Sail.data.business = {};            //数据结构清空
        var _id="",_url=this.getUrl;
        if(this.isUpdate()||this.isView()){ //如果是修改，则拼接URL， loaddata
            var gp = this.getUrlParameter;
            for(var i=0;i<gp.length;i++){
                var v = this.getRequest(gp[i]);
                _url+="&"+gp[i]+"="+v;
            }
            if(this.runMode=="debug"){
                alert("信息：修改操作时，获取数据的URL=\n\n"+_url);
            }
        }
        
        //------------------------------------------------------------------------
        //修改模式下， 通过postData请求数据，并根据数据构造组件
        //------------------------------------------------------------------------
        var o = this;
        var _data ={}; 
        var _callback_success = function(flag,getData){
        	debugger;
            Sail.data.business = getData;   //加载数据到全局数据对象中
            o.afterLoadData();              //执行加载数据完成后方法
            //debugger;
            o.beforeCreateWidgets();        //构造页面组件前，可能的在这里处理数据结构
            o.createWidgets();              //构造组件
            
            o.bindData();                   //绑定数据到组件
        };
        var _callback_failure = function(flag,_status){
            Ext.Msg.alert('提示：', '获取数据失败！！！'); return false;
        };
                
        this.postData(_url,_data,_callback_success,_callback_failure);
        return;
        
        //------------------------------------------------------------------------
        /*Ext.Ajax.request({
            url: _url,method: 'POST',params: {},
            success: function(action) {
                Sail.data.business = eval("("+action.responseText+")");
                o.bindData();
                o.afterLoadData();
            },
            failure: function() {
                Ext.Msg.alert('提示：', '网络异常！请刷新或检查网络！！'); return false;
            }
        });
        return true;*/
    },
    beforeLoadData:function(){return true;},
    afterLoadData : function(){},

    
    //===========================================================================================
    //方法： 
    //说明： 绑定数据到组件
    //===========================================================================================
    haveAppointedData : function(dataroot,dataList){
        eval("var _root="+dataroot);
        
        if(_root[dataList[0]]!=undefined) {
            if(dataList.length==1)
                return true;
            else{
                var newRoot = dataroot+"."+dataList[0];
                dataList.splice(0,1);
                return this.haveAppointedData(newRoot,dataList);
            }
        }
        else 
            return false;
    },
    dataInBusiness : function(root){
        var _fields = root.split(".");
        return this.haveAppointedData("Sail.data.business",_fields);
        
    },
    
    checkData : function(dataroot,dataList,widgetType){
        eval("var _root="+dataroot);
        
        if(_root[dataList[0]] ||_root[dataList[0]]=="") {
            if(dataList.length==1)
                return;
            else{
                var newRoot = dataroot+"."+dataList[0];
                dataList.splice(0,1);
                this.checkData(newRoot,dataList,widgetType);
            }
        }
        else {
            _root[dataList[0]]={};
            if(dataList.length==1){ 
                if(widgetType.indexOf("grid")!=-1)
                    _root[dataList[0]]=[];
                else{
                    //debugger;
                    _root[dataList[0]]="";
                }
                
                return;
            }
            else{
                var newRoot = dataroot+"."+dataList[0];
                dataList.splice(0,1);
                this.checkData(newRoot,dataList,widgetType);
            }
        }
    },
    
    bindData : function(){  
        //debugger;
        var r = this.bindRelation;
        var dataArray = [];
        for(var i=0,len=r.length;i<len;i++) {
            dataArray = [];
            //try{
                var w = ((typeof r[i]["widget"] == 'object')?r[i]["widget"]:$(r[i]["widget"]));
                if(w.type=="ext.grid") continue;
                
                if(r[i]["data"] instanceof Array){
                    //debugger;
                    for(var k=0;k<r[i]["data"].length;k++){
                        var fieldArray = r[i]["data"][k].split(".");
                        this.checkData("Sail.data.business",fieldArray,w.type);
                        var data = this.getObjFromBusiness(r[i]["data"][k]);
                        
                        dataArray.push(data);
                    }
                    w.bindData(r[i],dataArray);
                }else{
                    var fieldArray = r[i]["data"].split(".");
                    if(r[i]["result"])
                        fieldArray.push(r[i]["result"]);
                    
                    this.checkData("Sail.data.business",fieldArray,w.type);
                    
                    if(r[i]["data"]=="") continue;
                    var data = this.getObjFromBusiness(r[i]["data"]);
                    w.bindData(data);
                }
            //}catch(e){
            //    alert("信息：\n在执行bindData方法时，发生异常！"+e.message);
            //}
        }
            
        this.afterBindData();
    },
    afterBindData : function(){},
    
    //===========================================================================================
    //方法： run、runing 
    //说明： 入口
    //===========================================================================================
    beforeCreateWidgets : function(){
    },
    createWidgets : function(){
        this.arrangeSearch_run();       //如果存在，构造查询条件form
        this.arrangeDataForm_run();     //如果存在，构造新增修改表单
        this.initWidget();              //构造组件
        
        this.adjustWidget();
        this.loadOver();                //

        //try{
            addEvent2Widget();
        //}catch(e){
          //  alert("错误：\n\n为组件绑定事件时发生！ 发生在addEvent2Widget方法中！\n\n"+e.message);
        //}
        this.afterRun();        
    },
    
    
    bindEvent2Widget : function(){
    },
    
    //===========================================================================================
    //方法： run、runing 
    //说明： 入口
    //===========================================================================================
    getOthers : function(){
    },

    runing_step1: function(){
//        var theObj = this;
//        
//        var _callbackSuccess = function(flag,getData){
//            if(getData.dataset!=undefined){
//                if(getData.dataset.others!=undefined){
//                    //debugger;
//                    if(getData.dataset.others.navi!=undefined){
//                        theObj.loginInfo.navi = getData.dataset.others.navi;
//                    }
//                    if(getData.dataset.others.operator!=undefined){
//                        theObj.loginInfo.operator = getData.dataset.others.operator;
//                    }
//                    if(getData.dataset.others.opername!=undefined){
//                        theObj.loginInfo.opername = getData.dataset.others.opername;
//                    }
//                    if(getData.dataset.others.opertype!=undefined){
//                        theObj.loginInfo.opertype = getData.dataset.others.opertype;
//                    }
//                    if(getData.dataset.others.operorgid!=undefined){
//                        theObj.loginInfo.operorgid = getData.dataset.others.operorgid;
//                    }
//                    if(getData.dataset.others.operorgname!=undefined){
//                        theObj.loginInfo.operorgname = getData.dataset.others.operorgname;
//                    }
//                    if(getData.dataset.others.opercode!=undefined){
//                        theObj.loginInfo.opercode = getData.dataset.others.opercode;
//                    }
//
//                    if(getData.dataset.others.factoryName!=undefined){
//                        theObj.loginInfo.factoryName = getData.dataset.others.factoryName;
//                    }
//                    if(getData.dataset.others.factoryID!=undefined){
//                        theObj.loginInfo.factoryID = getData.dataset.others.factoryID;
//                    }
//
//                    //-----------------------------------------------------------------------
//                    //取得页面按钮权限信息
//                    //-----------------------------------------------------------------------
//                    if(getData.dataset.others.operfun!=undefined){
//                        theObj.loginInfo.operfun = getData.dataset.others.operfun;
//                    }
//                }
//            }
//            theObj.runing_step2();
//        };
//        
//        var _callbackFailure = function(flag,getData){
//            if(theObj.isList()){
//                theObj.loadOver();
//                Ext.Msg.alert('错误：','获取登录信息失败！！！');
//                return;
//            }
//            theObj.runing_step2();
//            return;
//        };
//
//        this.postData(this.naviRequest,{},_callbackSuccess,_callbackFailure);


        this.runing_step2();
    },
    
    runing_step2 : function(){
        Sail.apply(this,{widgets:Sail.data.widgets,mainDiv:Sail.get('mainDiv')});
        this.addRelation2Widgets();     //构造组件前，bindRelation(添加到组件定义中)        
        
        //debugger;
        //---------------------------------------------------------------------
        //---------------------------------------------------------------------
        if(this.beforeLoadData()){      //before方法返回true才执行加载数据方法
           
            if(!this.pauseLoadData) 
                this.loadData();
            else
                this.createWidgets();
        }else{                          //否则，直接执行组件创建主方法
            this.createWidgets();
        }
    },
    run : function(page){
    	
        this.sRequest = window.dialogArguments;
        if(this.runMode=="debug"){
            if(this.sRequest){
                alert("调试信息：\n\n mode="+this.sRequest.mode);
            }
        }
        var o = this;
        setTimeout(function(){Ext.onReady(o.runing_step1, o);},50);    
    },
    replaceField : function(_field){
        return _field.replaceAll(".",this.replaceChar);
    },
    addRelation2Widgets : function(){  
        var r = this.bindRelation;
        for(var i=0,len=r.length;i<len;i++) {
            try{
                var w = this.findWidgetBy(Sail.data.widgets,r[i]["widget"]);
                //-------------------------------------------------------------
                //处理表格绑定的多层次数据关系，统一替换为 replaceChar
                //-------------------------------------------------------------
                if(r[i]["id"]){
                    if(r[i]["id"].indexOf(".")!=-1)
                        r[i]["id"] = this.replaceField(r[i]["id"]);
                    
                }
                if(r[i]["sysflag"]){
                    if(r[i]["sysflag"].indexOf(".")!=-1)
                        r[i]["sysflag"] = this.replaceField(r[i]["sysflag"]);
                }
                
                if(r[i]["field"]){
                    for(var k=0;k<r[i]["field"].length;k++){
                        var o = r[i]["field"][k];
                        if(o.name){
                            if(o.name.indexOf(".")!=-1)
                                o["name"] = this.replaceField(o["name"]);
                        }
                    }
                }
                if(r[i]["col"]){
                    for(var k=0;k<r[i]["col"].length;k++){
                        var o = r[i]["col"][k];
                        if(o.dataIndex.indexOf(".")!=-1)
                            o["dataIndex"] = this.replaceField(o["dataIndex"]);
                        if(o.idIndex){
                            if(o.idIndex.indexOf(".")!=-1)
                                o["idIndex"] = this.replaceField(o["idIndex"]);
                        }
                    }
                }
                //-------------------------------------------------------------
                //-------------------------------------------------------------
                w.bindRelation = r[i];
            }catch(e){
                alert("绑定数据关系到组件时发生错误！！");
            }
        }
    },
    set : function(config){
        Ext.apply(this,config);
        
        if(this.postUrl=="") this.postUrl=this.serviceUrl_Save;
    },
    loadOver : function(){
        setTimeout(function(){Ext.get('loading').remove();Ext.get('loading-mask').fadeOut({remove:true});}, 100);
    },
    afterRun : function(){},
    
    //===========================================================================================
    //===========================================================================================
    open : function(_url,_mode,_data,w,h){
        var sendData = {
            mode : _mode,
            data : _data
        };
        var chrValue=window.showModalDialog(_url,sendData,'dialogWidth:'+w+'px;dialogHeight:'+h+'px;center:1;scroll:1;help:0;status:0');

        return chrValue;
    },
    setMode : function(_mode){
        if(this.sRequest){
            this.sRequest.mode=_mode;
        }else{
            this.sRequest = {};
            this.sRequest.mode=_mode;
        }
    },
    isUpdate : function(){
        if(this.sRequest){
            if(this.sRequest.mode=="update"){
                //Sail.data.business={};
                return true;
            }else{
                if(this.sRequest.mode=="view"){
                    return true;
                }
            }
        }
        return false;
    },
    isAdd : function(){
        if(this.sRequest){
            if(this.sRequest.mode=="add"){
                return true;
            }
        }
        return false;
    },
    isView : function(){
        if(this.sRequest){
            if(this.sRequest.mode=="view"){
                return true;
            }
        }
        return false;
    },
    isList : function(){
        if(!this.isUpdate()&&!this.isAdd()&&!this.isView()) return true;
        return false;
    },
    getRequest : function(){
        var a = arguments;
        var findname = (a.length==0)?'id':a[0];
        
        if(this.sRequest){
            var v = this.sRequest.data[findname];
            if(v){
                return v;
            }else{
                if(sc.runMode=="debug")
                    alert("从 request 中取 ["+findname+"] 时，没有找到该值 ！");
                return "";
            }
        }
        if(sc.runMode=="debug")
            alert("从 request 中取 ["+findname+"] 时，request为空 ！");
            
        return "";
    },
                
    //===========================================================================================
    //方法： save
    //说明： 保存方法入口
    //===========================================================================================
    getDataObj2 : function(o,pList){
        if(pList.indexOf(".")==-1) return o[pList];
        var ps = pList.split(".");
        pList = pList.replace(ps[0]+".","");
        return this.getDataObj2(o[ps[0]],pList);
    },

    getDataObj : function(o,pList){
        if(pList.indexOf(".")==-1) return o;
        var ps = pList.split(".");
        pList = pList.replace(ps[0]+".","");
        return this.getDataObj(o[ps[0]],pList);
    },
    dealWithGridBusinessData : function(grid){
        alert("dealWithGridBusinessData 方法已废弃！");
        return;
        
        eval("var dataObj = Sail.data.business."+grid.bindRelation["data"]);
        var results = dataObj[grid.bindRelation["result"]];
        if(results.length==1){
            var newObj = {};
            Ext.apply(newObj,dataObj[grid.bindRelation["result"]][0]);
            dataObj[grid.bindRelation["result"]]={};
            Ext.apply(dataObj[grid.bindRelation["result"]],newObj);
        }
        
    },
    beforeUpdateBusiness : function(){},
    updateBusiness : function(){
        this.beforeUpdateBusiness();
        
        var sb = Sail.data.business;                //取得业务逻辑数据对象
        var tb = this.bindRelation;                 //取得组件与业务逻辑数据对象绑定关系
        
        for(var i=0;i<tb.length;i++){               //遍历绑定关系
            var o = $(tb[i].widget);                //从绑定关系中取得某个页面组件
            
            if(!(tb[i].data)) continue;
            
            if(tb[i].data instanceof Array){
                //debugger;
                for(var k=0;k<tb[i].data.length;k++){
                    
                    if(o.type.indexOf("grid")==-1){         //组件类别 不是 表格
                        var p = tb[i].data[k].split(".");   //取得绑定关系中绑定的数据关系（业务逻辑数据对象的某个属性）
                        
                        //debugger;
                        var pList = (o.type.indexOf("grid")==-1)?tb[i].data[k]:tb[i].data[k]+"."+tb[i].result;
                        var d = this.getDataObj(Sail.data.business,pList);  //取得实际的业务逻辑数据对象属性的引用
                        var v = o.getValue(k);               //直接取得组件当前值
                        d[p[p.length-1]] = v;               //当前值 赋予 业务逻辑数据对象 相应的属性
                    }else{
                        //d[tb[i].result]= new Array();
                        //this.dealWithGridBusinessData(o);   //执行表格的存储映射方法（从grid.store映射到 Sail.data.business）
                    }
                }
            }else{
                
                if(o.type.indexOf("grid")==-1){         //组件类别 不是 表格
                    var p = tb[i].data.split(".");          //取得绑定关系中绑定的数据关系（业务逻辑数据对象的某个属性）
                    
                    //debugger;
                    var pList = (o.type.indexOf("grid")==-1)?tb[i].data:tb[i].data+"."+tb[i].result;
                    var d = this.getDataObj(Sail.data.business,pList);  //取得实际的业务逻辑数据对象属性的引用

                    var v = o.getValue();               //直接取得组件当前值
                    d[p[p.length-1]] = v;               //当前值 赋予 业务逻辑数据对象 相应的属性
                }else{
                    //d[tb[i].result]= new Array();
                    //this.dealWithGridBusinessData(o);   //执行表格的存储映射方法（从grid.store映射到 Sail.data.business）
                }
            }
        }
    },
    business2JSON: function(){
        var teststr = Sail.data.business.toJSONString();
        if(this.runMode=="debug") {
            Ext.MessageBox.show({
                title: 'POST JSON',
                msg: 'copy出去看。。。',
                width:600,
                closable:false,
                buttons: {cancel : "关闭"},
                prompt:true,
                multiline: true,
                value:teststr
            });
        }
        return teststr;
    },
    afterUpdateBusiness : function(){
    },
    
    showLoadMask : function(_msg){
        //var msg = (arguments.length==0)?"保存数据，请稍后......":arguments[1];
        //this.loadMask = (this.loadMask==undefined)?new Ext.LoadMask(Ext.get('mainDiv'),{msgCls:'x-mask-saveing',msg:_msg}):this.loadMask;

        this.loadMask = new Ext.LoadMask(Ext.get('mainDiv'),{msgCls:'x-mask-saveing',msg:_msg});
        this.loadMask.show();

    },
    hideLoadMask : function(){
        this.loadMask.hide();
    },
    
    saveBusiness : function(){
        
        if(this.saveFlag) return;
        this.saveFlag = true;

        var a = arguments;
        var closeMode   = "";
        var successFunc = null;
        var failureFunc = null;
        
        //-----------------------------------------------------------
        //处理参数
        //-----------------------------------------------------------
        if(a.length==1){
            if(typeof a[0] =='string'){
                closeMode = a[0];
            }else{
                closeMode   = a[0].mode;
                successFunc = a[0].success;
                failureFunc = a[0].failure;
            }
        }
        //-----------------------------------------------------------
        //-----------------------------------------------------------
        if(!this.checkSaveData()){
            this.saveFlag = false;
            return;
        }
        
        if(this.runMode=="debug") {
            alert("信息：\n\n保存数据时，POST URL="+this.postUrl);
        }
        this.showLoadMask('保存数据，请稍后......');
        //this.loadMask = (this.loadMask==undefined)?new Ext.LoadMask(Ext.get('mainDiv'),{msgCls:'x-mask-saveing',msg:'保存数据，请稍后......'}):this.loadMask;
        //this.loadMask.show();

        //-----------------------------------------------------------
        //-----------------------------------------------------------
        this.updateBusiness();          //处理大结构数据
        this.afterUpdateBusiness();     //调用在处理数据后，post到后台前的空方法
        
        //-----------------------------------------------------------
        //-----------------------------------------------------------
        var postInfo = this.business2JSON();
        var theObj = this;
        Ext.Ajax.request({
            url: this.postUrl,method: 'POST',params: {"dataset":postInfo},
            success: function(action) {
                var getObj = eval('('+action.responseText+')');
                
                theObj.loadMask.hide();
                theObj.saveFlag = false;
                if(successFunc !=null) {    
                    successFunc.call(this,action,getObj);
                }
                else{
                    if(getObj.dataset.response.success=='true'){
                        //Ext.Msg.alert('系统提示:','数据保存成功！　　　　　　　');
                        //alert("数据保存成功！");
                        Ext.Msg.alert('系统提示:','数据保存成功！　　　　　　　');
                        
                        if(window.returnValue === undefined)
                            window.returnValue='ok';
                        
                        if(closeMode=="close") window.close();
                    }else{
                        Ext.Msg.alert('系统提示:',getObj.dataset.response.content+'　　　　　　　');
                    }
                }
            },
            failure: function(action) {
                theObj.loadMask.hide();
                theObj.saveFlag = false;
                if(failureFunc !=null) {
                    failureFunc.call(this,action);
                }else{
                    //alert("提示\n\n保存数据失败！");
                    Ext.Msg.alert('系统提示:','数据保存失败！　　　　　　　');
                    //if(closeMode=="close") window.close();
                }
            }
        });
    },
    close : function(){
        window.close();
    },

    //==========================================================================
    //表单验证
    //==========================================================================
    needCheck : function(w){
        //debugger;
        var checkList = "ext.input,ext.numInput,ext.selectField,ext.sDate,ext.combox,ext.textArea";
        if(checkList.indexOf(w.type)==-1) return false;
        
        if(w.getOCD().style.display=='none' ) return false;
        
        switch(w.type){
            case "ext.input":
                if(w.allowBlank !=undefined && w.allowBlank ==false) return true;
                if(w.maxLength  !=undefined ) return true;
                break;
            case "ext.numInput":
                if(w.allowBlank    !=undefined && w.allowBlank ==false) return true;
                if(w.allowNegative !=undefined ) return true;
                if(w.maxLength     !=undefined ) return true;
                if(w.maxValue      !=undefined ) return true;
                break;
            case "ext.selectField":
                if(w.allowBlank !=undefined && w.allowBlank ==false) return true;
                break;
            case "ext.sDate":
                if(w.allowBlank !=undefined && w.allowBlank ==false) return true;
                break;
            case "ext.combox":
                if(w.allowBlank !=undefined && w.allowBlank ==false) return true;
                break;
            case "ext.textArea":
                if(w.allowBlank !=undefined && w.allowBlank ==false) return true;
                if(w.maxLength  !=undefined ) return true;
                break;
        }

        return false;
    },
    getCheckInfo : function(w){
        var ci = w.getCheckInfo();
        
        return this.getErrorInfo(ci);
    },
    getErrorInfo : function(ci){
        var errorStr = "";
        if(ci.minLength !=undefined) errorStr+="最小长度为"+ci.minLength+"；";
        if(ci.maxLength !=undefined) errorStr+="最大长度为"+ci.maxLength+"；";
        if(ci.minValue  !=undefined) errorStr+="最小值为"+ci.minValue+"；";
        if(ci.maxValue  !=undefined) errorStr+="最大值为"+ci.maxValue+"；";
        
        if(ci.allowBlank !=undefined)       errorStr+="不能为空；";
        if(ci.allowDecimals !=undefined)    errorStr+="不能为小数；";
        if(ci.allowNegative !=undefined)    errorStr+="不能为负数；";
        if(ci.decimalPrecision !=undefined) errorStr+="小数位数为"+ci.decimalPrecision+"；";
        
        return errorStr;
    },
    checkDataForm : function(_title){
        //-----------------------------------------------------------
        var nowContainer = null;
        for(var i=0;i<this.dataContainer.length;i++){
            if(this.dataContainer[i].title==_title){
                nowContainer = this.dataContainer[i];
                break;
            }
        }
        if(nowContainer==null) return true;
        
        //-----------------------------------------------------------
        var errorMsg = "";
        for(var i=0;i<nowContainer.subWidgets.length;i++){
            var wDefine = nowContainer.subWidgets[i];
            var widget = $(wDefine.id);
            if(this.needCheck(widget)){
                var value  = widget.el.getValue();
                var flag   = widget.el.validateValue(value);
                if(!flag){
                    var errorInfo = this.getCheckInfo(widget);
                    var _type = ((widget.title=="")?widget.name:widget.title);
                    errorMsg +="<tr style='font:normal 12px verdana;'><td align=right nowrap style='color:#ff0000'>"+_type+"</td><td>&nbsp;数据录入不正确！&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>";
                }
            }
        }
        if(errorMsg!=""){
            errorMsg = "<table>"+errorMsg+"</table>";
            this.showMessage("数据效验",errorMsg,"info");
            return false;
        }

        return true;
    },   
    checkGrid3 : function(_title){
        var _grid = $(_title);
        if(_grid.allowBlank !=undefined){
            if(!_grid.allowBlank){
                if(_grid.getCount()<=0){
                    this.showMessage("数据效验",'表格不能为空！',"info");
                    return false;
                }
            }
        }

        var col     = _grid.bindRelation.col;
        var editor  = _grid.bindRelation.editor;
        var msgList = [];
        
        var cmConfig = _grid.el.getColumnModel().config;
        var beginIndex = 2;
        //if(_grid.colNumber) beginIndex++;
        //if(_grid.colCheckbox) beginIndex++;
                
        for(var i=0;i<_grid.getCount();i++){
            var record = _grid.el.getStore().getAt(i);
            for(var j=0;j<col.length;j++){
                if(editor[j].config !=undefined){
                    if(cmConfig[j+beginIndex].hidden) continue;
                    
                    var dataIndex  = col[j].dataIndex;
                    var allowBlank = editor[j].config.allowBlank;
                    if(allowBlank==false){
                        var _value = record.get(dataIndex);
                        if(_value==undefined || _value.toString()==''){
                            var header = col[j].header.replace('*','');
                            var msg = "列表中第 <font color=#ff0000>"+(i+1)+"</font> 行记录，<font color=#ff0000>【"+header+"】</font>值不允许为空！";
                            var msgTr="<tr style='font:normal 12px verdana;'><td align=left nowrap style='color:#000000'>"+msg+"</td></tr>";
                            msgList.push(msgTr);
                        }
                    }
                }
            }
        }
        
        if(msgList.length>0){
            var msg= "<table>"+msgList.join('')+"</table>";
            this.showMessage("数据效验",msg,"info");
            return false;
        }
        
        return true;            
    },
    
    checkEditGrid : function(_title){
        //debugger;
        var _grid = $(_title);
        if(_grid.allowBlank !=undefined){
            if(!_grid.allowBlank){
                if(_grid.getCount()<=0){
                    this.showMessage("数据效验",'表格不能为空！',"info");
                    return false;
                }
            }
        }
        
        var col     = _grid.bindRelation.col;
        var editor  = _grid.bindRelation.editor;
        var msgList = [];
        
        var cmConfig = _grid.el.getColumnModel().config;
        var beginIndex = 0;
        if(_grid.colNumber) beginIndex++;
        if(_grid.colCheckbox) beginIndex++;
                
        for(var i=0;i<_grid.getCount();i++){
            var record = _grid.el.getStore().getAt(i);
            for(var j=0;j<col.length;j++){
                if(editor[j].config !=undefined){
                    if(cmConfig[j+beginIndex].hidden) continue;
                    
                    var dataIndex  = col[j].dataIndex;
                    var allowBlank = editor[j].config.allowBlank;
                    if(allowBlank==false){
                        var _value = record.get(dataIndex);
                        if(_value==undefined || _value.toString()==''){
                            var header = col[j].header.replace('*','');
                            var msg = "列表中第 <font color=#ff0000>"+(i+1)+"</font> 行记录，<font color=#ff0000>【"+header+"】</font>值不允许为空！";
                            var msgTr="<tr style='font:normal 12px verdana;'><td align=left nowrap style='color:#000000'>"+msg+"</td></tr>";
                            msgList.push(msgTr);
                        }
                    }
                }
            }
        }
        
        if(msgList.length>0){
            var msg= "<table>"+msgList.join('')+"</table>";
            this.showMessage("数据效验",msg,"info");
            return false;
        }
        
        return true;    
    },
    
    findWidgetsNeedCheck :function(){
        var returnInfo = [];
         
        for(var i=0;i<Sail.data.widgets.length;i++){
            
            var w = Sail.data.widgets[i];
            
            if(w.type=="ext.tabs"){
                var subs = w.subWidgets;
                for(var k=0;k<subs.length;k++){
                    if(subs[k].type=='ext.gridE')
                       returnInfo.push({id:subs[k].id,type:subs[k].type}); 
                }
            }else if(w.type=="ext.myForm"){
                returnInfo.push({id:w.title,type:w.type}); 
            }else if(w.type=="ext.gridE"||w.type=="ext.grid3"){
                returnInfo.push({id:w.id,type:w.type}); 
            }else{
                ;
            }
        }
        return returnInfo;
    },
    
    checkSaveData :function(){
        
        var checkList = [];
        if(arguments.length==0){
            checkList = checkList.concat(this.findWidgetsNeedCheck());
        }
        //debugger;
        for(var i=0;i<checkList.length;i++){
            var check = checkList[i];
            
            if(check.type=='ext.gridE'){
                var _result = this.checkEditGrid(check.id);
                if(!_result) return _result;
            }else if(check.type=='ext.myForm'){
                var _result = this.checkDataForm(check.id);
                if(!_result) return _result;
            }else if(check.type=='ext.grid3'){
                var _result = this.checkGrid3(check.id);
                if(!_result) return _result;
            }
            else{
                ;
            }
        }
        return true;
    },
    
    //===========================================================================================
    //方法： addFormWidget and some fn
    //说明： 根据描述创建表单，及表单编辑项目
    //===========================================================================================
    addFormWidget : function(config){
        var o = {        
            "id"             : "ext.myForm.0",
            "name"           : "表单",
            "type"           : "ext.myForm",
            "title"          : "查询条件",
            "left"           : 5,
            "top"            : 5,
            "height"         : 120,
            "canbeContainer" : true,
            "autoWidth"      : true,
            "subWidgets"     : []
        };
        o.id = "ext.myForm."+this.widgetIDIndex;
        this.widgetIDIndex++;
        if(config) Ext.apply(o,config);
        return o;
    },
    addWidgt2Form : function(wConfig,form){
        if(wConfig instanceof Array){
            for(var i=0,len=wConfig.length;i<len;i++){
                
                if(wConfig[i].brother){
                    if(wConfig[i].brother instanceof Array){
                        for(var k=0;k<wConfig[i].brother.length;k++){
                            wConfig[i].brother[k].isBrotherItem = true;
                            var wo = this.createSearchItem(wConfig[i].brother[k]);
                            form.subWidgets.push(wo);
                        }
                    }else{
                        wConfig[i].brother.isBrotherItem = true;
                        var wo = this.createSearchItem(wConfig[i].brother);
                        form.subWidgets.push(wo);
                    }
                }
                var wo = this.createSearchItem(wConfig[i]);
                form.subWidgets.push(wo);
            }
        }else{
            var wo = this.createSearchItem(wConfig);
            form.subWidgets.push(wo);

            if(wConfig[i].brother){
                if(wConfig[i].brother instanceof Array){
                    for(var k=0;k<wConfig[i].brother.length;k++){
                        wConfig[i].brother[k].isBrotherItem = true;
                        var wo = this.createSearchItem(wConfig[i].brother[k]);
                        form.subWidgets.push(wo);
                    }
                }else{
                    wConfig[i].brother.isBrotherItem = true;
                    var wo = this.createSearchItem(wConfig[i].brother);
                    form.subWidgets.push(wo);
                }
            }else{
                var wo = this.createSearchItem(wConfig[i]);
                form.subWidgets.push(wo);
            }

        }
    },  
    createSearchItem : function(wc){
        //debugger;
        
        var iConfig = {
            "name"           : "",
            "left"           : 1,
            "top"            : 1,
            "width"          : 94,
            "height"         : 21,
            "canbeContainer" : false,
            "ownerTab"       : -1
        };

        if(this.sRequest==null) this.sRequest = window.dialogArguments;
        if(this.isView()) iConfig.readOnly = true;
        
        var _id="ext."+wc.stype+"."+this.widgetIDIndex;
        this.widgetIDIndex++;
        var _type="ext."+wc.stype;
        iConfig.id = _id;
        iConfig.type = _type;

        //if(this.isView()&&iConfig.type=='ext.button') iConfig.disabled = true;
        
        Ext.apply(iConfig,wc);
        return iConfig;        
    },
    addForm :function(subs,config){
        var o = this.addFormWidget(config);
        this.addWidgt2Form(subs,o);
        Sail.data.widgets.push(o);
        return o;
    },
    findFormItem : function(form,title){
        var scon = form.subWidgets;
        for(var i=0,len=scon.length;i<len;i++){
            if(scon[i]["id"]==title) return scon[i];
            if(scon[i]["name"]==title) return scon[i];
            if(scon[i]["title"]==title ) return scon[i];
        }
        alert("初始化表单时，没有找到表单项目："+title+"！");
        return null;
    },
    getMainDivWidth : function(){
        return Sail.get('mainDiv').offsetWidth;
    },
    
    //======================================================================================
    //方法： 
    //说明： 表单项目排列
    //======================================================================================
    arrangeFormItem_core : function(formContainer,arrangeRule){
        var mg= {left:10,right:20,top:10,bottom:10},row = {height:20,space:10},cell={width:0,space:20};
        var form = {el:formContainer,width:0,height:0,barheight:22},ar = arrangeRule,arlen= ar.length;
        if(arlen==0) return;
        //debugger;
        
        //------------------------------------------------------------------------
        //回写form宽度、高度
        //------------------------------------------------------------------------
        form.width = this.getMainDivWidth()-form.el.left*2;            //设置form宽度          
        form.el.width  = form.width;
        //------------------------------------------------------------------------
        //计算列宽度
        //------------------------------------------------------------------------
        var havePercent = false;
        var percentInfo = [];
        var cellCount = 0;
        for(var i=0;i<arlen;i++){
            var o = ar[i];
            if(o.align!="left" && o.align!="right"){
                if(o.percent) {
                    havePercent = true;
                    percentInfo = percentInfo.concat(o.percent);
                }
                cellCount=(cellCount<o.sub.length)?o.sub.length:cellCount;
            }
        }
        
        cell.width = new Array(cellCount);
        if(!havePercent){
            var _cellWidth = (form.width-mg.left-mg.right-cell.space*(cellCount-1))/cellCount;
            for(var i=0;i<cellCount;i++)
                cell.width[i]= _cellWidth;
        }else{
            var _allWidth = form.width-mg.left-mg.right-cell.space*(cellCount-1);
            for(var i=0;i<percentInfo.length;i++){
                cell.width[i]= _allWidth*percentInfo[i]/100;
            }
        }
        //debugger;
        //------------------------------------------------------------------------
        //布局各行各列
        //------------------------------------------------------------------------
        var _top = mg.top;
        //debugger;
        for(var i=0;i<arlen;i++){
            var o = ar[i];
            //var _top = mg.top+row.height*i+row.space*i;
            
            switch(o["align"]){
                case "left" :
                    var pRight = [0];                    
                    for(var k=0,len=o["sub"].length;k<len;k++){
                        var w = this.findFormItem(form["el"],o["sub"][k]);
                        w.left = ((k==0)?mg.left:0)+k*(1)+pRight[k];
                        w.top = _top;
                        pRight.push(w.left+w.width);
                    }
                    _top+=row.height+row.space;
                    break;
                case "right" :
                    break;
                case "left-right" :
                    var pRight = [];                    
                    pRight[0] = mg.left;
                    var _rowHeight = row.height;
                    
                    for(var k=0;k<o["sub"].length;k++){
                        var w = this.findFormItem(form["el"],o["sub"][k]);
                        w.top = _top;
                        if(parseInt(w.height,10)>_rowHeight) _rowHeight = parseInt(w.height,10);
                        
                        if(w.colspan){
                            _width = cell.space*(w.colspan-1);
                            for(var mm=0;mm<w.colspan;mm++){
                                _width+=cell.width[k+mm];
                            }
                        }
                        else
                            _width = cell.width[k];
                            
                        //_width = (w.colspan)?(cell.width*w.colspan+cell.space*(w.colspan-1)):cell.width[k];
                        
                        var wArray = [];
                        wArray.push(w);
                        
                        if(w.brother){
                            if(w.brother instanceof Array){
                                for(var bindex=0;bindex<w.brother.length;bindex++){
                                    var findName = (w.brother[bindex].title=="")?w.brother[bindex].name:w.brother[bindex].title;
                                    var wb = this.findFormItem(form["el"],findName);
                                    wb.top = _top;
                                    wArray.push(wb);
                                }
                            }else{
                                var findName = (w.brother.title=="")?w.brother.name:w.brother.title;
                                var wb = this.findFormItem(form["el"],findName);
                                wb.top = _top;
                                wArray.push(wb);
                            }
                        }
                        wi_width = _width/wArray.length;
                        var widths = [];
                        var _left=pRight[k];
                        for(var wIndex=0;wIndex<wArray.length;wIndex++){
                            wArray[wIndex].width= wi_width;
                            wArray[wIndex].left = _left;
                            _left+=+wi_width;
                        }
                        pRight.push(w.left+_width+cell.space);
                    }
                    _top+=_rowHeight+row.space;
                    break;
            }
        }        
        form.height = _top-row.space+mg.bottom+form.barheight;
        form.el.height = form.height;
    },
    
    //======================================================================================
    //方法： 
    //说明： 新增一块表单录入项目
    //======================================================================================   
    addDataForm : function(subs,config){
        var o = this.addForm(subs,config);
        
        this.dataContainer.push(o);
    },
    setDataForm : function(aInfo){
        //this.dataArrange = this.dataArrange.concat(aInfo);
        this.dataArrange.push(aInfo);
    },
    arrangeDataForm_run : function(){
        for(var i=0;i<this.dataContainer.length;i++){
            this.arrangeFormItem_core(this.dataContainer[i],this.dataArrange[i]);
        }
    },
    
    //===========================================================================================
    //方法： 
    //说明： 
    //===========================================================================================
    addSearch : function(subs,config){
        var o = this.addForm(subs,config);
        this.SearchContainer = o;
    },
    arrangeSearch : function(aInfo){
        this.searchArrange = this.searchArrange.concat(aInfo);
    },
    arrangeSearch_run : function(){
        this.arrangeFormItem_core(this.SearchContainer,this.searchArrange);
    },
    getSearch : function(){
        var a = arguments;
        var _search = new Sail.stringBuffer();
        var gridUrl =(a.length==0)?"":a[0].url;

        if(gridUrl!="") _search.append(gridUrl);
        
        var form = this.SearchContainer;
        for(var i=0,len=form.subWidgets.length;i<len;i++){
            var w = form.subWidgets[i];
            if(w.type.indexOf("button")!=-1) continue;
            
            var o = $((w.title=="")?w.name:w.title);
            var v = o.getValue();
            var f = "";
            
            if(w.dataIndex){
                f=w.dataIndex;
                if(v!=-1 && v!="" && v){
                    _search.append("&");
                    _search.append(f);
                    _search.append("=");
                    _search.append(encodeURI(v));
                }
            }    
            /*
            else{
                alert("组织查询条件时，没有找到组件： ["+w.title+"] 的 DataIndex！");
                return "";
            }*/
        }
        return _search.toString();        
    },
    resetForm : function(){
        
        var formName   = (arguments.length==1)?arguments[0]:"查询条件";
        var subWidgets = [];
        
        for(var i=0;i<Sail.data.widgets.length;i++){
            if(Sail.data.widgets[i].title==formName){
                subWidgets = Sail.data.widgets[i].subWidgets;
            }
        }
        
        for(var i=0;i<subWidgets.length;i++){
            var wName = (subWidgets[i].title=="")?subWidgets[i].name:(subWidgets[i].name!=undefined&&subWidgets[i].name!='')?subWidgets[i].name:subWidgets[i].title;
            
            var w = $(wName);
            
            switch(subWidgets[i].type){
                case 'ext.button':
                    break;
                case 'ext.input':
                    w.setValue("");
                    break;
                case 'ext.numInput':
                    w.setValue("");
                    break;
                case 'ext.combox':
                    //debugger;
                    w.setValue("");
                    break;
                case 'ext.sDate':
                    w.setValue("");
                    break;
                case 'ext.selectField':
                    w.setDataObj(["",""]);
                    break;
                case 'ext.textArea':
                    w.setValue("");
                    break;
                case 'ext.checkInput':
                    break;
                    
            }
        }
    },
    //======================================================================================
    //方法： 
    //说明： 
    //======================================================================================   
    getYear:function(){
        var dt = new Date();
        var y = dt.getYear();
        return y;
        
        //var m = dt.getMonth()+1;      //原烟业务年度才需要此判断
        //return (m<7)?y-1:y;
    },
    getMonth : function(){
        var dt = new Date();
        return dt.format('n');
    },
    getDay : function(){
        var dt = new Date();
        return dt.format('Ymd');
    },
    
    changeObj4Business : function(_obj){
        var newobj = {};
        var changeFlag = false;
        
        for(var p in _obj){
            if(p.indexOf(this.replaceChar)!=-1){
                changeFlag = true;
                var ps = p.split(this.replaceChar);
                var tmpObj = null;
                
                for(var i=0;i<ps.length;i++){
                    //debugger;
                    if(newobj[ps[i]]) {
                        tmpObj = newobj[ps[i]];
                        continue;
                    }
                    else{
                        if(i==0)
                            newobj[ps[i]] =(i==(ps.length-1))?_obj[p]:{};
                        else
                            tmpObj[ps[i]] = (i==(ps.length-1))?_obj[p]:{};
                            
                        tmpObj = newobj[ps[i]];
                    }
                    
                    //if(i==(ps.length-1)) tmpObj = _obj[p];
                }
            }
        }       
        if(changeFlag)
            return newobj;
        else{
            Ext.apply(newobj,_obj);
            return newobj;
        }
        //return (changeFlag)?newobj:_obj;
    },
    
    createSubObj : function(fo,subs){
        if(subs.length==1) {
            fo[subs[0]]="";
            return fo[subs[0]];
        }
        
        fo[subs[0]] = {};
        var first = subs.shift();
        return this.createSubObj(fo[first],subs);
        
    },
    
    getSubObj:function(fo,subs){
        try{
            if(subs.length==1) return fo[subs[0]];

            var pp = (subs[0].indexOf("[")==-1)?"":subs[0].split("[")[1].replace("]","");
            fo = (subs[0].indexOf("[")==-1)?fo[subs[0]]:fo[subs[0].split("[")[0]][pp];

            //fo = fo[subs[0]];
            subs.splice(0,1);
            return this.getSubObj(fo,subs);
        }catch(e){
            alert("获得指定对象的子对象时发生异常:"+e.message+",估计是拼写错误...");
            return null;
        }
    },
    
    getObjFromPostData : function(postData,subs){
        if(subs instanceof Array){
            return this.getSubObj(postData,subs);
        }else{
            return this.getSubObj(postData,subs.split("."));
        }
    },
    
    getObjFromBusiness:function(subs){
        if(subs instanceof Array){
            return this.getSubObj(Sail.data.business,subs);
        }else{
            return this.getSubObj(Sail.data.business,subs.split("."));
        }
    },
    getActualRow : function(root,row){
        this.fieldFlag  = (this.bindRelation.sysflag)?this.bindRelation.sysflag:"sysFlag";
        if(root.length){
            var index = 0;
            for(var i=0;i<root.length;i++){
                if(root[i][this.fieldFlag]!=undefined){
                    if(root[i][this.fieldFlag].toString()=='1'){
                        if(index==row) return i;
                        index++;
                    }
                }
            }
        }
        return row;
    },
    
    getActualRowByID : function(root,idField,idValue){
        this.fieldFlag  = (this.bindRelation.sysflag)?this.bindRelation.sysflag:"sysFlag";
        if(root.length){
            var index = 0;
            for(var i=0;i<root.length;i++){
                if(root[i][this.fieldFlag]!=undefined){
                    if(root[i][this.fieldFlag].toString()=='1'){
                        if(index==row) return i;
                        index++;
                    }
                }
            }
        }
        return row;
    },

    setBusinessData:function(root,row,dataIndex,dataValue){
        var saveObj = null;
        //debugger;
        row = this.getActualRow(root,row);
        
        //if(root instanceof Array){
        if(root.length){
            if(dataIndex.indexOf(this.replaceChar)!=-1){
                var indexArray = dataIndex.split(this.replaceChar);
                var last = indexArray.pop();
                //debugger;
                saveObj = this.getSubObj(root[row],indexArray);
                saveObj[last] = dataValue;
            }else{
                root[row][dataIndex] = dataValue;
            }
        }
        else{
            if(dataIndex.indexOf(this.replaceChar)!=-1){
                var indexArray = dataIndex.split(this.replaceChar);
                var last = indexArray.pop();
                saveObj = this.getSubObj(root,indexArray);
                saveObj[last] = dataValue;
            }else{
                root[dataIndex] = dataValue;
            }
        }
    },
    setBusinessAfterEdit2 : function(w,o){
        var dataObj = this.getObjFromBusiness(w.bindRelation["data"]+"."+w.bindRelation["result"]);   //取子对象
        var cm = o.grid.colModel;

        var dataIndex = cm.getDataIndex(o.column);
        var dataValue = o.record.get(dataIndex);   //取值

        if(cm.config[o.column].idIndex){    //是否包含ID绑定字段
            var idValue = cm.getCellEditor(o.column,o.row).field.getByDataValue();
            this.setBusinessData(dataObj,o.row,cm.config[o.column].idIndex,idValue);  //保存到数据结构
        }
        
        this.setBusinessData(dataObj,o.row,dataIndex,dataValue);    //保存到数据结构
    },

    setBusinessAfterEdit : function(w,o){
        var dataObj = this.getObjFromBusiness(w.bindRelation["data"]+"."+w.bindRelation["result"]);   //取子对象
        var cm = o.grid.colModel;

        if(arguments.length==2){
            var dataIndex = cm.getDataIndex(o.column);
            var dataValue = o.record.get(dataIndex);   //取值
    
            if(cm.config[o.column].idIndex){    //是否包含ID绑定字段
                var idValue = cm.getCellEditor(o.column,o.row).field.getByDataValue();
                this.setBusinessData(dataObj,o.row,cm.config[o.column].idIndex,idValue);  //保存到数据结构
            }
            
            if(cm.getCellEditor(o.column,o.row).field.getXType()=="datefield"){
                var copyDate = dataValue.clone();
                var strDate = copyDate.format('Ymd');
                this.setBusinessData(dataObj,o.row,dataIndex,strDate);    //保存到数据结构
            }
            else
                this.setBusinessData(dataObj,o.row,dataIndex,dataValue);    //保存到数据结构
        }else if(arguments.length==3 && arguments[2]){
            var colCount = cm.getColumnCount();
            for(var i=0;i<colCount;i++){
                var dataIndex = cm.getDataIndex(i);
                if(dataIndex =="") continue;
                
                var dataValue = o.record.get(dataIndex);   //取值
        
                if(cm.config[i].idIndex){    //是否包含ID绑定字段
                    var idValue = cm.getCellEditor(i,o.row).field.getByDataValue();
                    this.setBusinessData(dataObj,o.row,cm.config[i].idIndex,idValue);  //保存到数据结构
                }
                
                
                if(cm.getCellEditor(i,o.row)!=undefined){
                    if(cm.getCellEditor(i,o.row).field.getXType()=="datefield"){
                        if(dataValue=='') 
                            this.setBusinessData(dataObj,o.row,dataIndex,'');    //保存到数据结构
                        else{
                            var copyDate = dataValue.clone();
                            var strDate = copyDate.format('Ymd');
                            this.setBusinessData(dataObj,o.row,dataIndex,strDate);    //保存到数据结构
                        }
                    }                
                    else
                        this.setBusinessData(dataObj,o.row,dataIndex,dataValue);    //保存到数据结构
                }
                else
                    this.setBusinessData(dataObj,o.row,dataIndex,dataValue);    //保存到数据结构
            }
        }
            
    }
}



/*------------------------------------------------------------------------------------------------------\
|                                               快捷方法集合                                            |
\------------------------------------------------------------------------------------------------------*/
var sys_findedWidget = {};
function $(){
    var a = arguments;
    if(a.length==1){
        //debugger;
        if(sys_findedWidget[a[0]]) return sys_findedWidget[a[0]];
        
        var o = sc.getWidgetByID(a[0]);
        if(o==null){
            o = sc.getWidgetByName(a[0]);
            if(o==null){
                o=sc.getWidgetByTitle(a[0]);
            }
        }
        
        if(o==null){
            alert("应用$方法时，没有找到指定的组件【"+a[0]+"】！");
        }else{
            if(o instanceof Array){
                //debugger;
                alert("应用$方法时，发现重复定义的组件！重复定义了【"+a[0]+"】！");
            }
            else{
                sys_findedWidget[a[0]]=o;
                return o;
            }
        }
        
    }else if(arguments.length==2){
    
    }else if(arguments.length==3){
        var o = sc.getEl(a[0])
        o.on(a[1],a[2]);
    }else{
    }
}

function $2(){
    var a = arguments;
    if(a.length==1){
        //debugger;
        if(sys_findedWidget[a[0]]) return sys_findedWidget[a[0]];
        
        var o = sc.getWidgetByID(a[0]);
        if(o==null){
            o = sc.getWidgetByName(a[0]);
            if(o==null){
                o=sc.getWidgetByTitle(a[0]);
            }
        }
        
        if(o==null){
            return null;
        }else{
            if(o instanceof Array){
                alert("应用$方法时，发现重复定义的组件！重复定义了【"+a[0]+"】！");
                return null;
            }
            else{
                sys_findedWidget[a[0]]=o;
                return o;
            }
        }
        
    }else if(arguments.length==2){
    
    }else if(arguments.length==3){
        var o = sc.getEl(a[0])
        o.on(a[1],a[2]);
    }else{
    }
    return null;
}

function $T(v){
    var o = sc.getWidgetDefineByProperty("title",v)
    return o;
}
var sc = new Sail.pageConsole();







































/*------------------------------------------------------------------------------------------------------\
|                                          编辑器组件基类 Sail.widget                                   |
|-------------------------------------------------------------------------------------------------------|
|作者：于俊杰                                                                                           |
|时间：2008-02-27 创建并注释                                                                            |
|说明：                                                                                                 |
|-------------------------------------------------------------------------------------------------------|
|             【对象】                    |                          【说明】                           |
|-------------------------------------------------------------------------------------------------------|
| Sail.widget                             | 对象：                                                      |
|-------------------------------------------------------------------------------------------------------|
|                                       Copyright (c) 2007 YuJunJie                                     |
\------------------------------------------------------------------------------------------------------*/
Sail.widget = function(config){
    this.id;
    this.type;
    this.name;
    this.type;
    this.left;
    this.top;
    
    this.zIndex = 10;
    this.width;
    this.height;

    //-------------------------------------------------------------------------------------------------
    this.add2Win   = null;
    this.add2Group = null;
    this.el        = null;                 //封装对象实体，例如 封装grid 对应的是 layout
    this.OCD       = null;                 //封装容器对象 object Container Div
    this.mustMark  = "<font color=#ff0000>*</font>";
    
    //-------------------------------------------------------------------------------------------------
    Sail.apply(this, config);
    
    this.rowEvents = ["查看","修改"];
}


Sail.widget.prototype = {

    setCheck : function(config){
        Ext.apply(this,config);
        Ext.apply(this.el,config);
        var flag   = this.el.validateValue(this.el.getValue());
        
        if(flag){
            this.el.el.removeClass(this.el.invalidClass);
        }else{
            this.el.el.addClass(this.el.invalidClass);            
        }
    },
    getCheckInfo:function(){
        var ci={};
        return ci;
    },

    move2 : function(l,t){
        this.setLeft(l);
        this.setTop(t);
    },
    
    setTop : function(t){
        this.OCD.style.top = t;
        this.top = t;
    },
    setLeft : function(l){
        this.OCD.style.left = l;
        this.left = l;
    },
    
    getLeft : function(){
        return this.OCD.style.left;
    },

    setBoxWidth : function(w){
        this.width += w-this.boxWidth;
        this.setWidth(this.width);
    },
    setWidth : function(){
        var inputDivWidth  = this.width - this.titleWidth ;                 //计算模拟输入框宽度
        
        inputDivWidth = (this.titleWidth==0)?inputDivWidth:inputDivWidth-4; //没有标题，不需要加间隔空白
        inputDivWidth = (inputDivWidth<0)?10:inputDivWidth;

        this.inputDiv.style.width = inputDivWidth;                         //设置宽度
        this.el.setWidth(inputDivWidth+3);

        this.boxWidth = inputDivWidth;
    },
    setHeight:function(h){
        this.OCD.style.height = h;
        this.height = h;
        this.el.setHeight((this.type=='ext.myForm')?h-20:h);
    },
    
    refresh : function(){
        if( this.titleDiv && this.inputDiv ){

            var _innerText = (this.title=="")?"":this.title+"：";
            var _tmpText = this.mustMark+((_innerText.indexOf('*')!=-1)?_innerText.replace("*",''):_innerText);
            var _innerHTML  =(this.allowBlank!=undefined && this.allowBlank==false)?_tmpText:((_innerText.indexOf('*')!=-1)?_tmpText:_innerText);

            this.titleDiv.innerHTML = _innerHTML;
            //this.titleDiv.innerText = (this.title=="")?"":this.title+"：";
            
            this.titleWidth = this.titleDiv.offsetWidth;             //获得标题实际尺寸

            var inputDivLeft   = this.titleWidth + 4;;
            var inputDivWidth  = this.width - this.titleWidth -4;

            this.inputDiv.style.left  = inputDivLeft;
            this.inputDiv.style.width = inputDivWidth;

            this.el.setWidth(inputDivWidth);
        }
    },
    
    //-------------------------------------------------------------------------
    getOCD      : function() {  return this.OCD;    },

    hide : function(){
        this.getOCD().style.display="none";
    },
    show : function(){
        this.getOCD().style.display="";
    },
    
    addEvent : function(eventName){
        var rowEventList = ","+this.rowEvents.join(",")+",";
        if(rowEventList.indexOf(","+eventName+",")==-1)
            this.rowEvents.push(eventName);
    },
    
    addListener: function(e,fn){
        var rowEventList = ","+this.rowEvents.join(",")+",";
        var eName = e;
        
        if(this.el!=null){
            if(e=="select"){
                var theObj = this;
                this.el.addListener(e,function(e,r,i){
                    var t = r.get(theObj.fieldText);
                    var v = r.get(theObj.fieldValue);
                    fn.call(e,t,v,r);
                });
            }else if(e=="beforeclick"){
                var theObj = this;
                if(theObj.type.indexOf("selectField")!=-1){
                    this.el.addListener("beforeclick",function(o){
                        fn.call(e,o);
                    });
                }
            }else if(e=="datachange"&&this.type=="ext.selectField"){
                var theObj = this;
                this.el.addListener("datachange",function(sf){
                    var _value =theObj.getValue();
                    var _text  =theObj.getText();
                    var _data  =sf.getDataObj();
                    fn.call(e,_text,_value,_data,theObj);
                });
            }
            else if(rowEventList.indexOf(","+e+",")!=-1){
                if(this.type.indexOf("grid")!=-1){
                    var theObj = this;
                    this.el.addListener("cellclick",function(g,r,c,e){
                        var ch = g.getColumnModel().getColumnHeader(c);
                        
                        var cs = g.getView().getColumnData()[c];
                        var ds = g.store;
                        var record = ds.getAt(r);
                        var text = cs.renderer(record.data[cs.name], {}, record, r, c, ds);
                        text = ""+text;
                        if(text.indexOf(">")==-1) return;
                        if(text.indexOf("<")==-1) return;
                        if(text.indexOf('checkbox')!=-1) return;
                        
                        text = text.split(">")[1].split("<")[0];
                        //debugger;
                        //if(text.indexOf(eName)!=-1){
                        //if(eName.indexOf(text)!=-1){
                        if(eName==text){
                            var record = g.getStore().getAt(r);
                            //if(theObj.canbeOperated(record)){
		                        var idname = theObj.getIDName();
		                        var id=record.get(idname);
		                        if(id)
		                            fn.call(e,id,r,record);
		                        else
		                            alert("失败：\n\n发生在查看事件中取记录ID时！\n\n没有找到ID！");
                            //}
                        }
                    });
                }
            }
            else if(e=="rowclick"){
                var theObj = this;
                var sm = this.el.getSelectionModel();
                sm.addListener("rowselect",function(_sm,_index,_r){
                    var idname = theObj.getIDName();
                    var id=_r.get(idname);
                    if(id)
                        fn.call(e,id,_index,_r);
                    else
                        fn.call(e,"",_index,_r);
                });
            }
            else if(e=="cellclick"){
                var theObj = this;
                this.el.addListener(e,function(g,r,c,e){
                    var record = g.getStore().getAt(r);
                    var colModel = g.getColumnModel();
                    var dataIndex  = colModel.getDataIndex(c);
                    var actionText = colModel.config[c].actionText;
                    
                    var header = g.getColumnModel().getColumnHeader(c);
                    
                    if(actionText){return;}
                    if(dataIndex!=""){
                        var value = record.get(dataIndex);
                        fn.call(e,r,c,record,dataIndex,value,header);
                    }
                });
            }
            else if(e=="celldblclick "){
                var theObj = this;
                this.el.addListener(e,function(g,r,c,e){
                    var record = g.getStore().getAt(r);
                    var colModel = g.getColumnModel();
                    var dataIndex  = colModel.getDataIndex(c);
                    var actionText = colModel.config[c].actionText;
                    
                    var header = g.getColumnModel().getColumnHeader(c);
                    
                    if(actionText){return;}
                    if(dataIndex!=""){
                        var value = record.get(dataIndex);
                        fn.call(e,r,c,record,dataIndex,value,header);
                    }
                });
            }
            else                
                this.el.addListener(e,fn,this);
        }
    },
    
    getIDName : function(){
        return (this.bindRelation)?(this.bindRelation.id)?this.bindRelation.id:"id":"id";
    },
    getValue : function(){
    },
    setValue : function(v){
    },
    setReadOnly: function(b){
    },
    setDisabled : function(b){
    },
    
    enable : function(){
    },
    disable : function(){
    },
    
    bindData : function(){
        var a = arguments;
        var d = (a.length==1)?a[0]:a[1];
        this.setValue(d);
    },
    //=================================================================================================
    //方法： Sail.widget.createContainerDiv
    //说明： 为组件创建默认容器
    //=================================================================================================
    createContainerDiv : function(){
        
        var nowWidth = this.width;
        
        if(this.autoWidth){
            var width_FatherDiv = (this.scrollflag)?this.add2Win.offsetWidth-16:this.add2Win.offsetWidth;
            
            if(this.autoWidthType=="right"){
                nowWidth = width_FatherDiv-this.left-5;
            }
            else
                nowWidth = width_FatherDiv-this.left*2;
        }
        
        //---------------------------------------------------------------------------------------------
        //创建组件容器层
        //---------------------------------------------------------------------------------------------
        var containerDiv  = document.createElement( "DIV" );    
        Sail.apply(containerDiv.style,{
            left    : this.left,
            top     : this.top,
            width   : nowWidth,
            height  : this.height,
            zIndex  : this.zIndex,
            position: "absolute",
            border  : "0px #ff0000 solid"
        });
        containerDiv.id = containerDiv.uniqueID;        //获取ID
        this.add2Win.appendChild(containerDiv);         //添加到设计窗口
        this.width = nowWidth;
        this.OCD = containerDiv;                        //记录组件容器对象
    },
    
    //=================================================================================================
    //方法： Sail.widget.beforeCreateWidget
    //说明： 
    //=================================================================================================
    beforeCreateWidget : function(){
        this.createContainerDiv();                      //创建组件容器层，并返回 this.OCD
    },

    //=================================================================================================
    //方法： Sail.widget.createWidgetElement
    //说明： 创建组件展现单元（组件本身）
    //=================================================================================================
    createWidgetElement : function(){
    },

    //=================================================================================================
    //方法： Sail.widget.create
    //说明： 
    //=================================================================================================
    create : function(config){
        
        Sail.apply(this,config);                        //应用对象属性
        this.beforeCreateWidget();                      //创建组件之前：创建默认容器
                
        //-----------------------------------------------------------------------------------------
        this.createWidgetElement();                     //【抛出去的接口方法】创建组件展现
        
        //-----------------------------------------------------------------------------------------
        this.add2Group.push(this);                      //添加组件到管理组
        
        //-----------------------------------------------------------------------------------------
        this.afterCreateWidget();
    },
    
    //=================================================================================================
    //方法： Sail.widget.afterCreateWidget
    //说明： 
    //=================================================================================================
    afterCreateWidget : function(){
        if(this.canbeContainer && this.subWidgets.length>0){
            
            var sonWidgetsDefine = [];
            Ext.apply(sonWidgetsDefine,this.subWidgets);
            this.subWidgets = [];
            
            for(var i=0,len=sonWidgetsDefine.length;i<len;i++){

                if(this.type=="ext.tabs"){
                    var _index = sonWidgetsDefine[i].ownerTab;
                    //debugger;
                    this.entity.setActiveTab(_index);
                    this.OCBC = this.entity.items.items[_index].body.dom;
                }
                
                sonWidgetsDefine[i].add2Win = this.OCBC;
                sonWidgetsDefine[i].add2Group = sc.el;
                
                var newWidget = eval("new Sail.widget."+sonWidgetsDefine[i].type+"();");
                newWidget.create(sonWidgetsDefine[i]);
            }
            sonWidgetsDefine = null;
            if(this.type=="ext.tabs"){
                this.entity.setActiveTab(0);
            }

        }
    }
}
















/*------------------------------------------------------------------------------------------------------\
|                                          编辑器组件基类 Sail.widget                                   |
|-------------------------------------------------------------------------------------------------------|
|作者：于俊杰                                                                                           |
|时间：2008-02-27 创建并注释                                                                            |
|说明：                                                                                                 |
|-------------------------------------------------------------------------------------------------------|
|             【对象】                    |                          【说明】                           |
|-------------------------------------------------------------------------------------------------------|
| Sail.widget.ext                         | 对象：                                                      |
|                                         |                                                             |
| Sail.widget.ext.grid                    | 对象：                                                      |
|                                         |                                                             |
| Sail.widget.ext.input                   | 对象：                                                      |
| Sail.widget.ext.combox                  | 对象：                                                      |
| Sail.widget.ext.button                  | 对象：                                                      |
| Sail.widget.ext.check                   | 对象：                                                      |
| Sail.widget.ext.radio                   | 对象：                                                      |
| Sail.widget.ext.textArea                | 对象：                                                      |
| Sail.widget.ext.form                    | 对象：                                                      |
| Sail.widget.ext.myForm                  | 对象：                                                      |
|                                         |                                                             |
| Sail.widget.ext.tree                    | 对象：                                                      |
|-------------------------------------------------------------------------------------------------------|
|                                       Copyright (c) 2007 YuJunJie                                     |
\------------------------------------------------------------------------------------------------------*/

Sail.widget.ext = function(config){
    Sail.apply(this, config);
    Sail.widget.ext.superclass.constructor.call(this);
}

Sail.extend(Sail.widget.ext,Sail.widget,{
});

Sail.widget.ext.scroller = function(config){
    Sail.apply(this, config);
    Sail.widget.ext.superclass.constructor.call(this);
}
Sail.extend(Sail.widget.ext.scroller,Sail.widget.ext,{
    
    getValue : function(){
    },
    setValue : function(v){
    },
    
    enable : function(){
    },
    disable : function(){
    },
    setSonWidth : function(w){
        this.el.style.width = w;
    },
    setSonHeight : function(h){
        this.el.style.height= h;
    },
    createWidgetElement:function(){

        var containerDiv = this.getOCD();                   //获得组件容器层
        containerDiv.style.overflowX=this.overflowX;
        containerDiv.style.overflowY=this.overflowY;
        containerDiv.style.border = '0px solid #dedede';
        //---------------------------------------------------------------------------------------------
        var bottomScrollSon = document.createElement( "DIV" );          //下滚动条 容器层 
        
        bottomScrollSon.style.backgroundColor="#ffffff"; 
        bottomScrollSon.style.border    = "#0000ff 0px solid";
        bottomScrollSon.style.left      = 0;
        bottomScrollSon.style.top       = 0;
        if(this.overflowX=='auto'){
            bottomScrollSon.style.width     = this.width;
            bottomScrollSon.style.height    = 1;
        }else{
            bottomScrollSon.style.width     = 1;
            bottomScrollSon.style.height    = this.height;
        }
        bottomScrollSon.style.zIndex    = 100;
        bottomScrollSon.style.position  = "absolute";

        containerDiv.appendChild( bottomScrollSon );               //添加到包裹容器

        
        //---------------------------------------------------------------------------------------------
        containerDiv.id = this.id+"_div";
        this.el  = bottomScrollSon;
        
    }
});


/**************************************************************************************************
* 对象： Sail.widget.ext.gridE
* 说明： 
*
**************************************************************************************************/
Sail.widget.ext.gridE = function(config){
    this.haveTitle = true;
    this.collapsible  = true;
    this.colNumber = true;
    this.colCheckbox = true;
    this.useDefautlFunc_add = true;
    this.useDefautlFunc_del = true;
    this.allowBlank = false;
    
    Sail.apply(this, config);
    Sail.widget.ext.superclass.constructor.call(this);

    this.tbarButtons    = [];
    this.btIDPrefix     = "gridE_tbar_bt_";
    this.modeField      = "enableFlag";
    this.creatorField   = "creator";
    this.dataMode       = "free";
    
    this.colStore = [];
    this.colStoreConfig = [];
    
    this.recordDefine = [];
    this.editors = {};
    this.nowEditInfo = null;
    this.auto2business = true;
    
    
    //-----------------------------------------------------------
    this.gridConfig = {            
        border:true,
        autoScroll:true,
        clicksToEdit:true,
        enableColumnMove:false,
        enableColumnResize:true,
        enableDragDrop:false,
        animCollapse:false
    };
}

Sail.extend(Sail.widget.ext.gridE,Sail.widget.ext,{
    
    beforeBindData : function(){},
    bindData : function(){
        var a = arguments,r=null,d=null;
        if(a.length==1){
            r = this.bindRelation;
            d = a[0];
        }else{
            r = a[0];
            d = a[1];
        }
        this.bindDataByArray(r,d);
    },
    
    haveChange : function(){
        try{
            return (this.el.store.getModifiedRecords().length==0)?false:true;
        }
        catch(e){
            return false;
        }
    },
    
    setHeader : function(col,header){
        this.el.getColumnModel().setColumnHeader(col,header);
    },
    setHeaders : function(beginCol,endCol,headers){
        var headerModel = this.el.getColumnModel();

        for(var i=beginCol;i<=endCol;i++){
            headerModel.setColumnHeader(i,headers[i-beginCol]);
        }
    },
    
    hideCols : function(cols){
        
        var hideInfo = (cols.length)?cols:[];
        var gridCM = this.el.getColumnModel();
        for(var i=0;i<hideInfo.length;i++)
            gridCM.setHidden(hideInfo[i],true);
        
        //this.el.getView().fitColumns(true,false);
        //this.el.getView().refresh();
    },
    showCols : function(cols){
        var hideInfo = (cols.length)?cols:[];
        var gridCM = this.el.getColumnModel();
        for(var i=0;i<hideInfo.length;i++)
            gridCM.setHidden(hideInfo[i],false);
    },
    bindDataByArray : function(_bindRelation,_dataArray){
        var r = _bindRelation;
        var d = _dataArray;
        
        var _sysflag = (r.sysflag==undefined)?"sysFlag":r.sysflag;
        
        if(r.col){  
            var fieldSource  = r.field;
            var resultSrouce = d[r.result];
            //-----------------------------------------------------------------------------------------
            var newData = [];
            if(resultSrouce.length){
                for(var i=0;i<resultSrouce.length;i++){
                    if(resultSrouce[i][_sysflag]==='0')
                        continue;
                    
                    var _index = newData.length;
                    newData[_index]=[];
                    
                    for(var j=0;j<fieldSource.length;j++){ 
                        var fieldName = fieldSource[j]["name"];
                        
                        if(fieldName.indexOf(sc.replaceChar)!=-1){
                            var fns = fieldName.split(sc.replaceChar);
                            newData[_index][j] = sc.getSubObj(resultSrouce[i],fns);
                        }
                        else
                            newData[_index][j] = (resultSrouce[i][fieldName]==undefined)?"":resultSrouce[i][fieldName]; 
                    }
                }
            }else{
                if(sc.isUpdate()||sc.isView()){
                    if(!(resultSrouce instanceof Array)){
                        if(resultSrouce[_sysflag]!=='0'){
                            newData[0]=[];
                            for(var j=0;j<fieldSource.length;j++){ 
                                var fieldName = fieldSource[j]["name"];
                                if(fieldName.indexOf(sc.replaceChar)!=-1){
                                    var fns = fieldName.split(sc.replaceChar);
                                    newData[0][j] = sc.getSubObj(resultSrouce,fns);
                                }
                                else
                                    newData[0][j] = resultSrouce[fieldSource[j]["name"]]; 
                            }
                        }
                    }
                }
            }
            this.dataArray = newData;
            
            //-----------------------------------------------------------------
            //构造store的reader时，如果name包含分级(.)，则替换为*
            //-----------------------------------------------------------------
            var newDSDefine = [];
            for(var i=0,len=fieldSource.length;i<len;i++){ 
                newDSDefine[i] = fieldSource[i]; 
            }
            //debugger;
            var newStore = new Ext.data.Store({     
		        proxy: new Ext.data.PagingMemoryProxy(this.dataArray),  //数据
		        reader: new Ext.data.ArrayReader({}, newDSDefine)       //行对象定义
            });
            
            //-----------------------------------------------------------------
            //-----------------------------------------------------------------
            var theGrid = this.el;
            theGrid.reconfigure(newStore,theGrid.getColumnModel());
            theGrid.getStore().load();
            //debugger;
        }
    },
    
    destroy: function(){
        this.el.destroy();
    },
    
    //=============================================================================================
    //20080725 重新创建的构造表格的方法
    //=============================================================================================
    /*
    config中配置项目：
    colNumber       true/false      是否包含序号列
    colCheckbox     true/false      是否包含选择列
    
    data            string          列表数据源 父
    result          string          列表数据源 属性名 root=data+'.'+result
    id              string          列表数据ID字段，唯一性标志
    sysflag         string          列表数据是否有效标志字段
    field           array           表格record对象包含的字段集合
    col             array           列定义
    editor          array           列编辑器定义
    
    smRowspan       number          如果列头有行合并，sm占据的行数
    usePlugins      string          如果表格有扩展，扩展的类型
    headers         array           如果表格有复杂表头，定义集合，包含行合并、列合并定义
    */
    haveField : function(fieldList,field){      //判断是否已包含知道指定字段
        for(var i=0,len=fieldList.length;i<len;i++){
            if(fieldList[i]["name"]==field) return true;
        }
        return false;
    },
    reSetConfig : function(config){             //重置config
        var br = this.bindRelation;
        config.colNumber  = (config.colNumber!=undefined)?config.colNumber:this.colNumber;
        config.colCheckbox= (config.colCheckbox!=undefined)?config.colCheckbox:this.colCheckbox;
        config.data       = (config.data!=undefined)?config.data:br.data;
        config.result     = (config.result!=undefined)?config.result:br.result;
        config.id         = (config.id!=undefined)?config.id:((br.id!=undefined)?br.id:"id");
        config.sysflag    = (config.sysflag!=undefined)?config.sysflag:((br.sysflag!=undefined)?br.sysflag:"sysFlag");
        config.field      = (config.field!=undefined)?config.field:br.field;
        config.col        = (config.col!=undefined)?config.col:br.col;
        config.editor     = (config.editor!=undefined)?config.editor:br.editor;
        config.smRowspan  = (config.smRowspan!=undefined)?config.smRowspan:br.smRowspan;
        config.usePlugins = (config.usePlugins!=undefined)?config.usePlugins:br.usePlugins;
        config.headers    = (config.headers!=undefined)?config.headers:br.headers;
        
        config.showTitle  = (config.showTitle!=undefined)?config.showTitle:this.showTitle;
        config.tbar       = (config.tbar!=undefined)?config.tbar:this.tbar;
        config.title      = (config.title!=undefined)?config.title:this.title;
        config.collapsible= (config.collapsible!=undefined)?config.collapsible:this.collapsible;
        config.border     = (config.border!=undefined)?config.border:this.border;
        
        config.dataArray  = (config.dataArray!=undefined)?config.dataArray:[];
        config.pageSize   = (config.pageSize!=undefined)?config.pageSize:null;
        
        config.recreate   = (config.recreate!=undefined)?config.recreate:false;
        
        this.bindRelation.col    = config.col;
        this.bindRelation.editor = config.editor;
    },
    createStore : function(config){             //创建store，保存在this.dataStore
        this.dataStore = null;
        this.dataArray = [].concat(config.dataArray);
        this.recordDefine = (config.field)?[].concat(config.field):[]; 
        
        if(!this.haveField(this.recordDefine,config.id))
            this.recordDefine.push({name:config.id,type:"string",defaultValue:""});
        if(!this.haveField(this.recordDefine,config.sysflag))
            this.recordDefine.push({name:config.sysflag,type:"string",defaultValue:"1"});

        this.dataStore = new Ext.data.Store({
	        proxy: new Ext.data.PagingMemoryProxy(this.dataArray),      //构造时，是空数据
	        reader: new Ext.data.ArrayReader({}, this.recordDefine)     //record定义
        });
    },
    createColModel : function(config){          //创建列模型，保存在this.cm
        var colModel= [];                                      
        this.cm     = null;
        this.sm     = null;
        this.aIndex = 0;
        
        var theObj = this;
        //-----------------------------------------------------------
        if(config.colNumber){
            colModel.push(new Ext.grid.RowNumberer());
            this.aIndex++;
        }
        if(config.colCheckbox){
            this.sm = new Ext.grid.CheckboxSelectionModel();
            if(config.smRowspan) this.sm.rowspan = config.smRowspan;
            colModel.push(this.sm);
            this.aIndex++;
        }
        
        //-----------------------------------------------------------
        this.colStore = [];
        this.colStoreConfig = [];
        for(var i=0;i<this.aIndex;i++){
            this.colStore.push("");                             //列编辑器数据结构全局
            this.colStoreConfig.push("");                       //列编辑器配置全局
        }

        //-----------------------------------------------------------
        
        for(var i=0,len=config.col.length;i<len;i++){           //遍历列模型定义，扩展属性
            
            config.col[i]["sortable"]   = false;
            config.col[i]["locked"]     = false;
            config.col[i]["id"]         = "col_"+i;
            config.col[i]["css"]        = "border-right:1px #EDEDED solid;";
            
            this.colStore.push("");                 //列编辑器数据结构全局
            this.colStoreConfig.push("");           //列编辑器配置全局
            
            if(sc.isView()){
                config.col[i]["editor"] ={};
            }else{
                config.col[i]["editor"] = this.createColEditor(i+this.aIndex,config.editor[i]);
            }
            if(config.editor[i].config){
                if(config.editor[i].config.allowBlank!=undefined){
                    if(config.editor[i].config.allowBlank==false){
                        if(config.col[i]['header']!=undefined)
                            if(config.col[i]['header'].indexOf('*')==-1)
                                config.col[i]['header']="<font style='font:normal 12px verdana; color:#ff0000'>*</font>"+config.col[i]['header'];
                    }
                }
            }
            
            if(config.editor[i].type=="comboBox"){
                var wConfig = config.editor[i].config;
                var _textField =(wConfig.fieldText)?wConfig.fieldText:"text";
                var _valueField=(wConfig.fieldValue)?wConfig.fieldValue:"code";
                eval("var tf = function(value,metadate,r,rowIndex,colIndex){ \n"
                    +"  var dataIndex = (theObj.el.getColumnModel().config[colIndex].nameIndex);\n"
                    +"  if(dataIndex==undefined) return '';\n"
                    +"  var _name = r.get(dataIndex);\n"
                    +" return (_name==''||_name==undefined)?'':_name;\n"
                    +"}\n");

                config.col[i]["renderer"] = tf;
            }else if(config.editor[i].type=="dateField"){
                eval("var formatDate = function(value){ return value ? value.dateFormat('Y-m-d') : '';}");
                config.col[i]["renderer"] = formatDate;
            }
            colModel.push(config.col[i]);
            
        }
        this.cm = new Ext.grid.ColumnModel(colModel);
        
        if(config.usePlugins!=undefined){
            var tmpArray = [];
            if(config.colNumber)
                tmpArray.push({header:"", rowspan:2});
                
            if(config.colCheckbox){
                 tmpArray.push(this.sm);
                 config.headers[0] = tmpArray.concat(config.headers[0]);
            }
            this.cm.headers = config.headers;
        }
        
    },
    createGridConfig : function(config){        //创建表格组件配置对象

        this.gridConfig.cm      = this.cm;
        this.gridConfig.width   = this.width;
        this.gridConfig.height  = this.height;
        this.gridConfig.store   = this.dataStore;

        if(config.usePlugins==undefined)
            this.gridConfig.renderTo= this.getOCD();

        if(config.usePlugins!=undefined){
            this.gridConfig.plugins= new Ext.ux.plugins.XGrid();
        }
        
        if(config.colCheckbox){
            this.gridConfig.sm  = this.sm;
        }
        
        if(config.border!=undefined){
            this.gridConfig.border  = config.border;
        }
        if(config.showTitle){
            this.gridConfig.title   = config.title;
            this.gridConfig.iconCls = "icon-grid";
        }
        if(config.collapsible){
            this.gridConfig.collapsible = config.collapsible;
        }

        if(config.tbar){
            var index=0;
            if(config.tbar instanceof Array)
                config.tbar.push({text: '　'});
            
            for(var i=0;i<config.tbar.length;i++){
                if(config.tbar[i]=="-") continue;
                config.tbar[i].id=this.btIDPrefix+index;
                index++;
                if(config.tbar[i].text=="新增")       config.tbar[i].iconCls="grid_add";
                else if(config.tbar[i].text=="删除")  config.tbar[i].iconCls="grid_del";
                else if(config.tbar[i].text=="　")    config.tbar[i].iconCls="grid_null";
                else config.tbar[i].iconCls="grid_bt";

                if(sc.isList()){
                    if(sc.runMode!=="debug") {
                        if(sc.haveOperFun(this.tbar[i].text,this.title)==false){
                            this.tbar[i].disabled=true;
                            this.tbar[i].hidden=true;
                        }
                    }
                }
                
                this.tbarButtons.push({text:config.tbar[i].text});
            }
            this.gridConfig.tbar = this.tbar;
        }
    
    },
    createGridEl : function(config){

        var grid = new Ext.grid.EditorGridPanel(this.gridConfig);

        if(config.usePlugins!=undefined){
            grid.render(this.OCD.id);
        }

        this.el  = grid;
        this.el.setWidth(this.OCD.offsetWidth);

        if(config.pageSize==null ||config.pageSize==undefined)
            this.el.getStore().load();
        else
            this.el.getStore().load({params:{start:0, limit:config.pageSize}});
    },
    
    reconfigureGrid:function(config){
        this.el.reconfigure(this.dataStore,this.cm);
        if(config.pageSize==null ||config.pageSize==undefined)
            this.el.getStore().load();
        else
            this.el.getStore().load({params:{start:0, limit:config.pageSize}});
    },
    
    addEvent2Grid : function(){
        var theObj = this;
        
        if(sc.isView()){
            for(var i=0,len=this.tbarButtons.length;i<len;i++){
                var bt = this.getButton(this.tbarButtons[i]["text"]);
                if(this.tbarButtons[i]["text"]!="　")
                    bt.hide();
            }
        }else{
            var bt = this.getButton("　");
            if(bt) bt.hide();
        }

        //this.tbarButtons[i]
        //-----------------------------------------------------------------------------------------
        //绑定默认的新增、删除按钮点击事件
        //-----------------------------------------------------------------------------------------
        var _widget = this;            
        if(this.useDefautlFunc_add&&this.getButton("新增"))
            this.getButton("新增").setHandler(function(){_widget.addNewRecordByButton();});
        if(this.useDefautlFunc_del&&this.getButton("删除")){                
            if(this.delRecordMode==='physical')
                this.getButton("删除").setHandler(function(){_widget.removeRecordDynamic();});
            else
                this.getButton("删除").setHandler(function(){_widget.removeRecord();});
        }

        //-----------------------------------------------------------------------------------------
        //-----------------------------------------------------------------------------------------
        this.el.on("beforeedit",function(o){
            //debugger;
            theObj.nowEditInfo = {};
            theObj.nowEditInfo.record   = o.record;
            theObj.nowEditInfo.field    = o.field;
            theObj.nowEditInfo.value    = o.value;
            theObj.nowEditInfo.oldValue = o.originalValue;
            theObj.nowEditInfo.row      = o.row;
            theObj.nowEditInfo.column   = o.column;
        });
        this.el.on("afteredit",function(o){
                      
            //if(!theObj.auto2business) return;   //是否自动映射到business
            //debugger;
            var cm = o.grid.colModel;           //取得列模型
            var idValue = "";                   //如果是selectField，取绑定的id字段    
            
            if(cm.config[o.column].idIndex){    //是否包含ID绑定字段
                idValue = cm.getCellEditor(o.column,o.row).field.getByDataValue();
                var _record = o.grid.store.getAt(o.row);
                _record.data[cm.config[o.column].idIndex] = idValue;
            }
            
            var dataObj = sc.getObjFromBusiness(theObj.bindRelation["data"]+"."+theObj.bindRelation["result"]);   //取子对象

            if(cm.config[o.column].nameIndex){    //是否包含 combox name 绑定字段
                nameValue = cm.getCellEditor(o.column,o.row).field.el.dom.value;
                var _record = o.grid.store.getAt(o.row);
                _record.set(cm.config[o.column].nameIndex,nameValue);
                
                sc.setBusinessData(dataObj,o.row,cm.config[o.column].nameIndex,nameValue);
            }

            var dataIndex = cm.getDataIndex(o.column);  //取当前列 dataIndex
            var dataValue = o.record.get(dataIndex);    //取值
            
            
            if(cm.config[o.column].idIndex){    //如果存在ID绑定字段
                sc.setBusinessData(dataObj,o.row,cm.config[o.column].idIndex,idValue);  //保存到数据结构
            }
            
            if(cm.getCellEditor(o.column,o.row).field.getXType()=="datefield"){
                var copyDate = dataValue.clone();
                var strDate = copyDate.format('Ymd');
                sc.setBusinessData(dataObj,o.row,dataIndex,strDate);    //保存到数据结构
            }
            else
                sc.setBusinessData(dataObj,o.row,dataIndex,dataValue);    //保存到数据结构
                
            theObj.afterCellEdit.call("",o);
            
        });
        this.el.on("cellclick",function(g,r,c,e){
            //debugger;
            if(sc.isView()) return;
            var ed =g.colModel.getCellEditor(c, r);
            if(ed){
                var type = ed.field.getXType();
                if(type=="combo"){
                    //debugger;
                    //ed.field.view.expand();
                }
            }
        });


    },
  
    reCreateGrid : function(){
        if(arguments.length!=1) return;
        if(typeof arguments[0]!='object' || (arguments[0] instanceof Array)) return;
        var config = arguments[0];

        //if(config.recreate) this.destroy();
        //----------------------------------------------------------------------
        //为创建表格，组织数据
        //----------------------------------------------------------------------
        this.reSetConfig(config);       //组织配置数据
        this.createStore(config);       //取得字段定义，创建 record、store
        this.createColModel(config);    //创建列模型
        this.createGridConfig(config);  //创建表格组件配置对象
        
        //----------------------------------------------------------------------
        //----------------------------------------------------------------------
        this.reconfigureGrid(config);
    },
    
    createWidgetElement:function(){
        var config = {};

        this.reSetConfig(config);       //组织配置数据
        this.createStore(config);       //取得字段定义，创建 record、store
        this.createColModel(config);    //创建列模型
        this.createGridConfig(config);  //创建表格组件配置对象
        
        this.createGridEl(config);
        this.addEvent2Grid();
    },

    createWidgetElement2:function(){
        //debugger;
        var r = this.bindRelation;
        if(r && r.col){
            var theObj = this,_id=(r.id)?r.id:"id",_sysflag=(r.sysflag)?r.sysflag:"sysFlag";
            
            this.dataArray = [];
            this.smRowspan  = r.smRowspan;
            this.usePlugins = r.usePlugins;
            this.headers    = r.headers;
            
            //-----------------------------------------------------------------------------------------
            //取得字段定义，构造record store
            //-----------------------------------------------------------------------------------------
            var rConfig = (r.field)?r.field:[]; 
            var fieldList = ",";
            for(var i=0;i<rConfig.length;i++)
                fieldList+=rConfig[i]["name"]+",";
            if(fieldList.indexOf(','+_id+',')==-1)
                rConfig.push({name:_id,type:"string",defaultValue:""});
            if(fieldList.indexOf(','+_sysflag+',')==-1)
                rConfig.push({name:_sysflag,type:"string",defaultValue:"1"});
            
            var dataStore = new Ext.data.Store({
		        proxy: new Ext.data.PagingMemoryProxy(this.dataArray),      //构造时，是空数据
		        reader: new Ext.data.ArrayReader({}, rConfig)               //record的结构
            });
            this.recordDefine = rConfig;
            
            //-----------------------------------------------------------------------------------------
            //构造列模型
            //-----------------------------------------------------------------------------------------
            var sm = null
            var _colModel= [];                                   //列模型
            if(this.colNumber)
                _colModel.push(new Ext.grid.RowNumberer());      //序号列
            if(this.colCheckbox){
                 sm = new Ext.grid.CheckboxSelectionModel();     //选择框列
                if(this.smRowspan) sm.rowspan = this.smRowspan;

                _colModel.push(sm);
            }
            
            for(var i=0;i<2;i++){
                this.colStore.push("");                 //列编辑器数据结构全局
                this.colStoreConfig.push("");           //列编辑器配置全局
            }

            for(var i=0;i<r.col.length;i++){            //遍历列模型定义，扩展属性
                
                r.col[i]["sortable"] = false;
                r.col[i]["locked"] = false;
                r.col[i]["id"]  = "col_"+i;
                r.col[i]["css"] = "border-right:1px #EDEDED solid;";
                
                this.colStore.push("");                 //列编辑器数据结构全局
                this.colStoreConfig.push("");           //列编辑器配置全局
                
                if(sc.isView()){
                    r.col[i]["editor"] ={};
                }else{
                    r.col[i]["editor"] = this.createColEditor(i+2,r.editor[i]);
                }
                if(r.editor[i].config){
                    if(r.editor[i].config.allowBlank!=undefined){
                        if(r.editor[i].config.allowBlank==false)
                        r.col[i]['header']="<font style='font:normal 12px verdana; color:#ff0000'>*</font>"+r.col[i]['header'];
                    }
                }
                
                if(r.editor[i].type=="comboBox"){
                    var wConfig = r.editor[i].config;
                    var _textField =(wConfig.fieldText)?wConfig.fieldText:"text";
                    var _valueField=(wConfig.fieldValue)?wConfig.fieldValue:"value";
                    eval("var tf = function(value,metadate,r,rowIndex,colIndex){ \n"
                        //+" debugger;\n"
                        +"  var dataIndex = (theObj.el.getColumnModel().config[colIndex].nameIndex);\n"
                        +"  if(dataIndex==undefined) return '';\n"
                        +"  var _name = r.get(dataIndex);\n"
                        +" return (_name==''||_name==undefined)?'':_name;\n"
                        +"}\n");

                    r.col[i]["renderer"] = tf;
                }else if(r.editor[i].type=="dateField"){
                    eval("var formatDate = function(value){ return value ? value.dateFormat('Y-m-d') : '';}");
                    r.col[i]["renderer"] = formatDate;
                }
                _colModel.push(r.col[i]);
            }
            var cm = new Ext.grid.ColumnModel(_colModel);
            
            if(this.usePlugins!=undefined){
                var tmpArray = [];
                if(this.colNumber)
                    tmpArray.push({header:"", rowspan:2});
                    
                if(this.colCheckbox){
                     tmpArray.push(sm);
                     this.headers[0] = tmpArray.concat(this.headers[0]);
                     //this.headers[0].push(sm);
                }
                cm.headers = this.headers;
            }

            
            //-----------------------------------------------------------------------------------------
            //配置可编辑表格config
            //-----------------------------------------------------------------------------------------
            var gConfig = {
                //viewConfig: {autoFill:true},
                autoScroll:true,
                clicksToEdit:true,
                store:dataStore,
                enableColumnMove:false,
                enableColumnResize:true,
                enableDragDrop:false,
                cm:cm,
                //width:this.width,height:this.height,
                //renderTo: this.getOCD(),
                animCollapse:false
                
            };
          
            if(this.usePlugins!=undefined){
                ;
            }else{
                gConfig.width = this.width;
                gConfig.height = this.height;
                gConfig.renderTo = this.getOCD();
            }
            
            if(this.border!=undefined){
                gConfig.border=this.border;
            }
            if(this.colCheckbox){
                gConfig.sm = sm;
            }
            if(this.showTitle){
                gConfig.title = this.title;gConfig.iconCls = "icon-grid";
            }
            if(this.tbar){
                var index=0;
                if(this.tbar instanceof Array)
                    this.tbar.push({text: '　'});
                
                for(var i=0;i<this.tbar.length;i++){
                    if(this.tbar[i]=="-") continue;
                    
                    this.tbar[i].id=this.btIDPrefix+index;
                    index++;
                    
                    if(this.tbar[i].text=="新增") this.tbar[i].iconCls="grid_add";
                    else if(this.tbar[i].text=="删除") this.tbar[i].iconCls="grid_del";
                    else if(this.tbar[i].text=="　") this.tbar[i].iconCls="grid_null";
                    else this.tbar[i].iconCls="grid_bt";
    
                    this.tbarButtons.push({text:this.tbar[i].text});
                }
                
                gConfig.tbar = this.tbar;
                
            }
            if(this.collapsible){
                gConfig.collapsible = this.collapsible;
            }
            if(this.usePlugins!=undefined){
                gConfig.plugins= new Ext.ux.plugins.XGrid();
            }
            
          
            var grid = new Ext.grid.EditorGridPanel(gConfig);
            this.el  = grid;

            if(this.usePlugins!=undefined){
                grid.render(this.OCD.id);
                grid.reconfigure(grid.store, grid.getColumnModel());
            }
            
            this.el.setWidth(this.OCD.offsetWidth);


            //-----------------------------------------------------------------------------------------
            //-----------------------------------------------------------------------------------------
            if(sc.isView()){
                for(var i=0,len=this.tbarButtons.length;i<len;i++){
                    var bt = this.getButton(this.tbarButtons[i]["text"]);
                    if(this.tbarButtons[i]["text"]!="　")
                        bt.hide();
                }
            }else{
                var bt = this.getButton("　");
                if(bt) bt.hide();
            }

            //this.tbarButtons[i]
            //-----------------------------------------------------------------------------------------
            //绑定默认的新增、删除按钮点击事件
            //-----------------------------------------------------------------------------------------
            var _widget = this;            
            if(this.useDefautlFunc_add&&this.getButton("新增"))
                this.getButton("新增").setHandler(function(){_widget.addNewRecordByButton();});
            if(this.useDefautlFunc_del&&this.getButton("删除"))                
                this.getButton("删除").setHandler(function(){_widget.removeRecord();});

            //-----------------------------------------------------------------------------------------
            //-----------------------------------------------------------------------------------------
            grid.on("beforeedit",function(o){
                //debugger;
                theObj.nowEditInfo = {};
                theObj.nowEditInfo.record = o.record;
                theObj.nowEditInfo.field = o.field;
                theObj.nowEditInfo.value = o.value;
                theObj.nowEditInfo.row = o.row;
                theObj.nowEditInfo.column = o.column;
            });
            grid.on("afteredit",function(o){
                //debugger;
                //if(!theObj.auto2business) return;   //是否自动映射到business
                
                var cm = o.grid.colModel;           //取得列模型
                var idValue = "";                   //如果是selectField，取绑定的id字段    
                
                if(cm.config[o.column].idIndex){    //是否包含ID绑定字段
                    idValue = cm.getCellEditor(o.column,o.row).field.getByDataValue();
                    var _record = o.grid.store.getAt(o.row);
                    _record.data[cm.config[o.column].idIndex] = idValue;
                }
                
                if(cm.config[o.column].nameIndex){    //是否包含 combox name 绑定字段
                    //debugger;
                    nameValue = cm.getCellEditor(o.column,o.row).field.el.dom.value;
                    var _record = o.grid.store.getAt(o.row);
                    //_record.data[cm.config[o.column].nameIndex] = nameValue;
                    
                    _record.set(cm.config[o.column].nameIndex,nameValue);
                    
                    
                }

                var dataIndex = cm.getDataIndex(o.column);                  //取当前列 dataIndex
                var dataValue = o.grid.store.getAt(o.row).get(dataIndex);   //取值
                //if(cm.getCellEditor(o.column,o.row).field.getXType()=="datefield")
                //dataValue = dataValue.format('Ymd');
                
                var dataObj = sc.getObjFromBusiness(theObj.bindRelation["data"]+"."+theObj.bindRelation["result"]);   //取子对象
                

                if(cm.config[o.column].idIndex){    //如果存在ID绑定字段
                    sc.setBusinessData(dataObj,o.row,cm.config[o.column].idIndex,idValue);  //保存到数据结构
                }
                
                if(cm.getCellEditor(o.column,o.row).field.getXType()=="datefield"){
                    var copyDate = dataValue.clone();
                    var strDate = copyDate.format('Ymd');
                    sc.setBusinessData(dataObj,o.row,dataIndex,strDate);    //保存到数据结构
                }
                else
                    sc.setBusinessData(dataObj,o.row,dataIndex,dataValue);    //保存到数据结构
                    
                theObj.afterCellEdit.call("",o);
                
            });
            grid.on("cellclick",function(g,r,c,e){
                //debugger;
                if(sc.isView()) return;
                var ed =g.colModel.getCellEditor(c, r);
                if(ed){
                    var type = ed.field.getXType();
                    if(type=="combo"){
                        //debugger;
                        //ed.field.view.expand();
                    }
                }
            });

        }
    },

    
    //=============================================================================================
    //=============================================================================================
    clearCombox : function(){
        if(sc.isView()) return;
        
        var col,disMode;
        if(arguments.length==0){
            return;
        }
        else if(arguments.length==1){
            col = arguments[0];
            disMode=true;
        }else {
            col = arguments[0];
            disMode=arguments[1];
        }
        var ed = this.editors["col_"+col];
        var xtype = ed.getXType();
        if(this.nowEditInfo)
            var row = this.nowEditInfo.row;
        else
            return;
        
        //debugger;
        if(xtype=="combo"){

            this.setFieldValue(col,row,"");

            var cm = this.el.colModel;
            var _record = this.el.store.getAt(row);
            //_record.data[cm.config[col].nameIndex] = "";
            this.el.getStore().getAt(row).set(cm.config[col].nameIndex,"");
            
            var _td = this.el.getView().getCell(row,col);
            _td.innerHTML = "&nbsp;";
            //debugger;
                
            ed.store.removeAll();
            if(disMode)
                ed.disable();
        }
    },
    clearEditor : function(col){
        this.clearCombox(col);
        return;
        
        var ed = this.editors["col_"+col];
        var xtype = ed.getXType();
        var row = this.nowEditInfo.row;
        
        //debugger;
        if(xtype=="combo"){
            for(var i=0;i<this.el.store.getCount();i++){
                this.setFieldValue(col,i,"");

                var cm = this.el.colModel;
                var _record = this.el.store.getAt(row);
                //_record.data[cm.config[col].nameIndex] = "";
                this.el.getStore().getAt(row).set(cm.config[col].nameIndex,"");
                
                var _td = this.el.getView().getCell(row,col);
                //debugger;
            }
                
            ed.store.removeAll();
        }
    },
    addListener2Editor : function(col,ename,fn){
        if(sc.isView()) return;
        
        var ed = this.editors["col_"+col];
        var xtype = ed.getXType();
        switch (xtype){
            case "numberfield":
                if(ename=="change"){
                    ed.addListener(ename,function(field,newValue,oldValue){
                        fn.call("",newValue,oldValue,field);
                    });
                }else if(ename=="blur"){
                    ed.addListener(ename,function(field){
                        fn.call("",field,field.getValue());
                    });
                }
                break;
            case "timeinput":
                if(ename=="change"){
                    ed.addListener(ename,function(field,newValue,oldValue){
                        fn.call("",newValue,oldValue,field);
                    });
                }else if(ename=="blur"){
                    ed.addListener(ename,function(field){
                        fn.call("",field,field.getValue());
                    });
                }
                break;
            case "datefield" :
                if(ename=="change"){
                    ed.addListener(ename,function(field,newValue,oldValue){
                        fn.call("",newValue,oldValue,field);
                    });
                }
                break;
            case "textfield":
                if(ename=="change"){
                    ed.addListener(ename,function(field,newValue,oldValue){
                        fn.call("",newValue,oldValue,field);
                    });
                }
                break;

            case "combo":
                if(ename=="select"){
                    ed.addListener(ename,function(e,r,i){
                        var t = r.get(ed.displayField);
                        var v = r.get(ed.valueField);
                        fn.call("",t,v);
                    });
                }
                if(ename=="change"){
                    ed.addListener(ename,function(field,newValue,oldValue){
                        fn.call("",newValue,oldValue,field);
                    });
                }
                if(ename=='beforeselect'){
                    ed.addListener(ename,function(field,record,index){
                        fn.call("",field,record,index);
                    });
                }
                break;
            case "selectfield":
                if(ename=="afterclick"){
                    ed.addListener(ename,function(sf){
                        //var _value =sf.getValue();
                        //var _text  =sf.getText();
                        var _data  =sf.getDataObj();
                        fn.call("",_data);
                    });
                }                
                else if(ename=="beforeclick"){
                    ed.addListener(ename,function(sf){
                        //var _value =sf.getValue();
                        //var _text  =sf.getText();
                        var _data  =sf.getDataObj();
                        fn.call("",_data);
                    });
                }                
            default : break;
        }
        
    },
    getNowEditInfo : function(){
        return this.nowEditInfo;
    },
    getCount : function(){
        return this.el.store.getCount();
    },
    getEditor : function(col,row){
        return this.el.getColumnModel().getCellEditor(col,row).field;
    },
    canbeOperated : function(r){
        if(this.dataMode=="purview"){
            var _creator = r.get(this.creatorField);
            var _loginer = sc.getUser();
            
            _creator = (_creator=='')?_loginer:_creator;
            return (_creator==_loginer)?true:false;
        }
        else 
            return true;


        /*if(this.dataMode=="purview")
            return (r.get(this.modeField)=="1")?true:false;
        else 
            return true;*/
    },
    
    //=============================================================================================
    //=============================================================================================
    setFieldValue : function(col,row,newValue){
        var cm = this.el.colModel;
        var dataIndex = cm.getDataIndex(col);
        if(this.el.getStore().getAt(row)){
            this.el.getStore().getAt(row).set(dataIndex,newValue);
        
            var theObj =this;
            eval("var dataObj = Sail.data.business."+theObj.bindRelation["data"]);
            if(dataObj[theObj.bindRelation["result"]] instanceof Array){
                var _results = dataObj[theObj.bindRelation["result"]];
                row = sc.getActualRow(_results,row);
                dataObj[theObj.bindRelation["result"]][row][dataIndex] = newValue;
            }
            else{
                dataObj[theObj.bindRelation["result"]][dataIndex] = newValue;
            }
        }
    },
    setTextByDataIndex : function(row,col,text){
        var cell = this.el.getView().getCell(row,col);
        cell.children[0].innerText = text;
    },
    
    setFieldValueByDataIndex : function(dataIndex,row,newValue,mode){
        if(this.el.getStore().getAt(row)){
            //this.el.getStore().getAt(row).editing = true;
            if(mode===true){
                this.el.getStore().getAt(row).editing = true;
                this.el.getStore().getAt(row).set(dataIndex,newValue);
                this.el.getStore().getAt(row).editing = false;
            }else
                this.el.getStore().getAt(row).set(dataIndex,newValue);

            var theObj = this;        
            var dataObj = sc.getObjFromBusiness(theObj.bindRelation["data"]+"."+theObj.bindRelation["result"]);   //取子对象

            sc.setBusinessData(dataObj,row,dataIndex,newValue);    //保存到数据结构
        }
    },
    changeEditor : function(column,config){
        if(sc.isView()) return;
        
        var c = this.editors["col_"+column],_fields = [];
        var xtype = c.getXType()

        switch (xtype){
            case "combo":
                //if(xtype=="combo")      this.setFieldValue(column,0,"");
                if(this.getCount()>0)   this.setFieldValue(column,0,"");        
                
                var _url = config.url;
                var _root       = (config.root)?config.root:"dataset.simplecombobox";
                var _textField  = (config.fieldText)?config.fieldText:"text";
                var _valueField = (config.fieldValue)?config.fieldValue:"code";
                
                _fields.push(_textField);
                _fields.push(_valueField);
                    
                //c.store.removeAll();
                c.store.proxy= new Ext.data.HttpProxy({url: _url, method: 'POST'});
        	    c.store.reader= new Ext.data.JsonReader({root: _root}, _fields);
        
                c.valueField   = _valueField;        
                c.displayField = _textField;      
                c.store.load();
                this.colStore[column] = c.store;
                break;
            default : break;
        }
    },
    changeCombox : function(config){
        if(sc.isView()) return;
        
        var o = config.clickObj;
        
        //debugger;
        var editor = this.getEditor(o.column,o.row);
        editor.lastQuery = null;

        editor.store.proxy.conn.url =config.url;

        var _root = (config.root)?config.root:'dataset.simplecombobox';
        var _fields = [];

        var _textField =(config.fieldText)?config.fieldText:"text";
        var _valueField=(config.fieldValue)?config.fieldValue:"code";
        _fields.push(_textField);
        _fields.push(_valueField);
	    editor.store.reader= new Ext.data.JsonReader({root:_root}, _fields);
	    
        editor.valueField   = _valueField;
        editor.displayField = _textField;
        editor.enable();
        return;
        var theObj = this;
        if(config.autoSelect!=undefined && config.autoSelect){
            editor.store.load();
            editor.store.on('datachanged',function(_store){
                
                var dValue = _store.data.items[1].data['value'];
                var dText  = _store.data.items[1].data['text'];
                
                theObj.setFieldValueByDataIndex('measureUnitId',o.row,dValue);
                theObj.setFieldValueByDataIndex('measureUnitId_name',o.row,dText);
            });
        }
    },
    createColEditor : function(col,ceDefine){
        var editor = null;
        var config = {};
        var to = this;
        
        switch (ceDefine.type){
            //-------------------------------------------------------------------------------------
            //-------------------------------------------------------------------------------------
            case "textField":
                Ext.apply(config,ceDefine.config);
                config.selectOnFocus = true;
                this.editors["col_"+col] = new Ext.form.TextField(config);
                break;
            //-------------------------------------------------------------------------------------
            //-------------------------------------------------------------------------------------
            case "comboBox":
                var store = null;
                
                var _fields = [];
                var _textField =(ceDefine.config.fieldText)?ceDefine.config.fieldText:"text";
                var _valueField=(ceDefine.config.fieldValue)?ceDefine.config.fieldValue:"code";
                _fields.push(_textField);
                _fields.push(_valueField);
                
                if(ceDefine.config.url && ceDefine.config.url!=""){
                    store = new Ext.data.Store({
            	        proxy: new Ext.data.HttpProxy({url: ceDefine.config.url}),
            	        reader: new Ext.data.JsonReader({root: ceDefine.config.root}, _fields)
                    });

                    //-----------------------------------------------------------------------------
                    //combox 加载模式判定
                    //-----------------------------------------------------------------------------
                    if(ceDefine.config.autoWidth!=undefined)
                        config.autoWidth = ceDefine.config.autoWidth;

                    if(ceDefine.config.maxHeight!=undefined)
                        config.maxHeight = ceDefine.config.maxHeight;
                    var _mode = (ceDefine.config.mode)?ceDefine.config.mode:"local";
                    if(_mode!='remote') store.load();
                }
                else
                    store = new Ext.data.SimpleStore({fields:_fields,data : []});
                
                
                this.colStore[col]=store;      //数据引用保存到组件属性中，按列
                this.colStoreConfig[col] = _fields;
                
                config ={
                    store: store,displayField:_textField,
                    //autoWidth:true,
                    //width:300,
                    //mode: 'remote',
                    autoShow : true,
                    name:_textField,
                    valueField:_valueField,
                    typeAhead: true,
                    triggerAction: 'all',
                    loadingText:"读取...",
                    emptyText:'未选择...',
                    selectOnFocus:true,
                    editable : false/*,
                    lazyInit : false    //*///日*/
                };
                
                config.mode = (ceDefine.config.mode)?ceDefine.config.mode:"local";
                this.editors["col_"+col] = new Ext.form.ComboBox(config);

                var theObj = this.editors["col_"+col];
                break;
            //-------------------------------------------------------------------------------------
            //-------------------------------------------------------------------------------------
            case "dateField":
                config = {format:"Y-m-d",readOnly:true,emptyText:"选择日期"};
                //config = {readOnly:true,emptyText:"选择日期"};
                Ext.apply(config,ceDefine.config);
                this.editors["col_"+col] = new Ext.form.DateField(config);
                break;
            //-------------------------------------------------------------------------------------
            //-------------------------------------------------------------------------------------
            case "timeInput":
                Ext.apply(config,ceDefine.config);
                config.maxLength = 5;
                config.selectOnFocus = true;
                this.editors["col_"+col] = new Ext.form.timeInput(config);
                break;
            //-------------------------------------------------------------------------------------
            //-------------------------------------------------------------------------------------
            case "numberField":
                Ext.apply(config,ceDefine.config);
                config.selectOnFocus = true;
                this.editors["col_"+col] = new Ext.form.NumberField(config);
                break;
            //-------------------------------------------------------------------------------------
            //-------------------------------------------------------------------------------------
            case "selectfield":
                
                config.allowBlank = true;
                config.blankText = "未选择...";
                config.showValue = (ceDefine.config.text)?ceDefine.config.text:"text";
                config.dataValue = (ceDefine.config.value)?ceDefine.config.value:"id";
                
                //config.readOnly  = true;
                Ext.apply(config,ceDefine.config);
                
                //debugger;
                this.editors["col_"+col] = new Ext.form.SelectField(config);
                break;
            //-------------------------------------------------------------------------------------
            //-------------------------------------------------------------------------------------
            case "selectfieldadvanced":
                
                config.allowBlank = true;
                config.blankText = "未选择...";
                config.showValue = (ceDefine.config.text)?ceDefine.config.text:"text";
                config.dataValue = (ceDefine.config.value)?ceDefine.config.value:"id";
                
                //config.readOnly  = true;
                Ext.apply(config,ceDefine.config);
                
                //debugger;
                this.editors["col_"+col] = new Ext.form.SelectFieldAdvanced(config);
                break;
            default:
                break;
        }
        
        return this.editors["col_"+col];
        
        //return editor;
    },
    getButtonIndexByText : function(text){
        for(var i=0,len=this.tbarButtons.length;i<len;i++){
            if(this.tbarButtons[i]["text"]==text) return i;
        }
        return -1;
    },
    getButton:function(key){
        var type =  typeof key;
        if(type=="string"){
            var index = this.getButtonIndexByText(key);
            if(index==-1) {
                //alert("没有找到符合条件的按钮！");
                return null;
            }
            var id = this.btIDPrefix+index;
            return this.el.getTopToolbar().items.get(id);
        }else if(type=="number"){
            key = (key==0)?0:key+1;
            return this.el.getTopToolbar().items.get(key);
        }else{
            alert("传递的参数错误！");
            return null;
        }
    },
    //=============================================================================================
    //记录操作
    //=============================================================================================
    createRecord :function(){
        //debugger;
        var setValues = {};
        if(arguments.length==1) setValues = arguments[0];       //20080728
        
        var dsDefine = this.recordDefine;
        var rowInfo = Ext.data.Record.create(dsDefine);
        var cd = {};
        for(var i=0;i<dsDefine.length;i++){
            if(setValues[dsDefine[i].name]!=undefined){
                cd[dsDefine[i].name] = setValues[dsDefine[i].name];
            }else{
                cd[dsDefine[i].name] = (dsDefine[i].defaultValue)?dsDefine[i].defaultValue:"";
            }
        }
        var p = new rowInfo(cd);
        return p;
    },
    addRecords : function(recordArray){
        //debugger;
        if(recordArray instanceof Array)
            for(var i=0;i<recordArray.length;i++)
                this.addnewRecord2Grid(recordArray[i]);
        else
            this.addnewRecord2Grid(recordArray);
        return;
        
        /*var _index = this.el.store.getCount();
        eval("var dataObj = Sail.data.business."+this.bindRelation["data"]);
        
        var results = dataObj[this.bindRelation["result"]];
        if(!(results instanceof Array)){
            dataObj[this.bindRelation["result"]]= new Array();
        }
        
        if(recordArray instanceof Array){
            for(var i=0;i<recordArray.length;i++)
                dataObj[this.bindRelation["result"]].push(recordArray[i].data);
        }else{
            dataObj[this.bindRelation["result"]].push(recordArray.data);
        }

        this.el.stopEditing();
        if(recordArray instanceof Array){
            for(var i=0;i<recordArray.length;i++){
                this.el.store.insert(_index+i, recordArray[i]);
            }
        }else{
            this.el.store.insert(_index, recordArray);
        }
        this.el.startEditing(_index, this.fEditor);*/
    },
    addNewRecord : function(dataObj){
        alert("addNewRecord 方法已废除。。。");
        return;
        /*
        var colInfo = Ext.data.Record.create(this.recordDefine);
        var cd = {};
        for(var i=0;i<this.recordDefine.length;i++){
            cd[this.recordDefine[i].name] = (dataObj[i].value)?dataObj[i].value:"";
        }
        var p = new colInfo(cd);
        this.addnewRecord2Grid(p);*/
    },
    addNewRecordByButton : function(){
        
        var dsDefine= this.recordDefine;
        var colInfo = Ext.data.Record.create(dsDefine);
        var cd = {};
        for(var i=0;i<dsDefine.length;i++){
            //debugger;
            if(dsDefine[i].type=="date"){
                cd[dsDefine[i].name] = new Date();
            }else{
                cd[dsDefine[i].name] = (dsDefine[i].defaultValue)?dsDefine[i].defaultValue:"";
            }
        }
        var p = new colInfo(cd);
        this.addnewRecord2Grid(p);
    },
    addnewRecord2Grid : function(p){
        //debugger;
        var _index = this.el.store.getCount();

        //-----------------------------------------------------------------------------
        //已修改 ---->标志自动保存，才做数据映射（映射到Sail.data.business）
        //通过动态设置 this.bindRelation.data来实现
        //-----------------------------------------------------------------------------
        var results = sc.getObjFromBusiness(this.bindRelation["data"]+"."+this.bindRelation["result"]);
        var o = sc.changeObj4Business(p.data);
        
        //-----------------------------------------------------------------------------
        //传值传引用啊...
        //-----------------------------------------------------------------------------
        var o2business = {};
        Ext.apply(o2business,o);
        for(var pr in o2business){
            if(typeof o2business[pr] =='object' && pr!='toJSONString'){
                if(o2business[pr] instanceof Date){
    	            var copyDate = o2business[pr].clone();
  	                var strDate = copyDate.format('Ymd');
	                o2business[pr] = strDate;
              	}
            }
        }

        
        if(results instanceof Array){
            results.push(o2business);
        }else{
            if(sc.isAdd()){
                var dataroot = sc.getObjFromBusiness(this.bindRelation["data"]);
                dataroot[this.bindRelation["result"]]= new Array();  
                dataroot[this.bindRelation["result"]].push(o2business);
            }else{
                var tmpobj = {};
                Ext.apply(tmpobj,results);
                var dataroot = sc.getObjFromBusiness(this.bindRelation["data"]);

                dataroot[this.bindRelation["result"]]= new Array();                
                dataroot[this.bindRelation["result"]].push(tmpobj);
                dataroot[this.bindRelation["result"]].push(o2business);

                //results= new Array();                
                //results.push(tmpobj);
                //results.push(o);
            }
        }
        //-----------------------------------------------------------------------------
        //-----------------------------------------------------------------------------
        this.el.stopEditing();
        this.el.store.insert(_index, p);
        this.el.startEditing(_index, 0);

        //-----------------------------------------------------------------------------
        //-----------------------------------------------------------------------------
        //debugger;
        return;


    },

    removeRecordDynamic :  function(){
        if(!(arguments.length==1 && arguments[0]==false)){
            //if(this.el.getSelections()) 
            
            var dels = this.el.getSelections();
            if(dels.length>0)
            {
                if(!confirm('真的要删除所选择的数据吗？')){
                    return;
                }
            }else{
                Ext.Msg.alert("提示：","请先选择记录，再进行删除操作！");
                return;
            }
        }
        
        this.fieldID    = (this.bindRelation.id)?this.bindRelation.id:"id";
        this.fieldFlag  = (this.bindRelation.sysflag)?this.bindRelation.sysflag:"sysFlag";
        //debugger;
        //sc.getActualRow
        
        eval("var dataObj = Sail.data.business."+this.bindRelation["data"]);
        var sdata = this.el.getSelections();
        this.el.stopEditing();
        
        //-----------------------------------------------------------
        //20081023 选择删除时，先获取被删除的记录序号，然后倒序排序
        //删除记录时，按照倒序进行删除
        //-----------------------------------------------------------
        var delIndex = [];
        for(var i=0;i<sdata.length;i++){
            var index = this.el.store.data.indexOf(sdata[i]);
            delIndex.push(index);
        }
        delIndex = delIndex.sort(function(a,b){
            return (a>b)?-1:1;
        });
        //debugger;
        var results = dataObj[this.bindRelation["result"]];        
        for(var i=0;i<delIndex.length;i++){
            var index = delIndex[i];
            
            try{
                //debugger;
                if(results instanceof Array)
                    dataObj[this.bindRelation["result"]].splice(index,1);
                else
                    dataObj[this.bindRelation["result"]]=[];
            }catch(e){
                alert("删除记录时发生异常！");
            }
        }
        
        for(var i=0;i<sdata.length;i++)
            this.el.store.remove(sdata[i]);

        this.el.startEditing(0, 0);
        this.el.getView().refresh();
    },

    removeRecord : function(){
        if(!(arguments.length==1 && arguments[0]==false)){
            //if(this.el.getSelections()) 
            
            var dels = this.el.getSelections();
            if(dels.length>0)
            {
                if(!confirm('真的要删除所选择的数据吗？')){
                    return;
                }
            }else{
                Ext.Msg.alert("提示：","请先选择记录，再进行删除操作！");
                return;
            }
        }
        
        this.fieldID    = (this.bindRelation.id)?this.bindRelation.id:"id";
        this.fieldFlag  = (this.bindRelation.sysflag)?this.bindRelation.sysflag:"sysFlag";
        //debugger;
        //sc.getActualRow
        
        eval("var dataObj = Sail.data.business."+this.bindRelation["data"]);
        var sdata = this.el.getSelections();
        this.el.stopEditing();
        
        for(var i=0;i<sdata.length;i++){
            var index = this.el.store.data.indexOf(sdata[i]);
            var results = dataObj[this.bindRelation["result"]];
            index = sc.getActualRow(results,index);
            try{
                //debugger;
                if(sdata[i].get(this.fieldID)==""){
                    if(results instanceof Array)
                        dataObj[this.bindRelation["result"]].splice(index,1);
                    else
                        dataObj[this.bindRelation["result"]]=[];
                }else{
                    if(results instanceof Array)
                        dataObj[this.bindRelation["result"]][index][this.fieldFlag]="0";
                    else
                        dataObj[this.bindRelation["result"]][this.fieldFlag]="0";;
                }
            }catch(e){
                alert("删除记录时发生异常！");
            }
        }
        
        for(var i=0;i<sdata.length;i++)
            this.el.store.remove(sdata[i]);

        this.el.startEditing(0, 0);
        this.el.getView().refresh();
    },
    removeAll : function(){
        /*if(!confirm('真的要删除所选择的数据吗？')){
            return;
        }*/
        this.el.getSelectionModel().selectAll();
        this.removeRecord(false);
        return;
        /*原有逻辑不正确，没有区分本次新增与读取数据 20080723
        this.el.store.removeAll();
        eval("var dataObj = Sail.data.business."+this.bindRelation["data"]);
        var results = dataObj[this.bindRelation["result"]];
        
        dataObj[this.bindRelation["result"]]=[];
        //debugger;
        */
    },
    afterCellEdit : function(o){
        
    }
});


/**************************************************************************************************
* 对象： Sail.widget.ext.grid
* 说明： 
*
**************************************************************************************************/
Sail.widget.ext.grid = function(config){
    this.colCheckbox  = false;  
    this.colNumber    = true;
    
    this.singleSelect = false;  
    this.collapsible  = true;
    
    Sail.apply(this, config);
    Sail.widget.ext.superclass.constructor.call(this);
    
    this.btIDPrefix     = "grid_tbar_bt_";
    this.selectedField  = "id";
    this.modeField      = "enableFlag";
    this.creatorField   = "creator";
    this.dataMode       = "free";
    this.tbarButtons    = [];
    
    this.store = null;
    this.createdGrid = false;
    
    this.selectIndex = -1;
    this.pageSize = 3;
}

Sail.extend(Sail.widget.ext.grid,Sail.widget.ext,{

    //=============================================================================================
    //=============================================================================================
    bindData : function(){
        //debugger;
    },
    //=============================================================================================
    //=============================================================================================
    load : function(){
        if(this.beforeLoad()==false) return;
        
        var a = arguments;
        var _url = (a.length==0)?this.url:a[0];
        this.url = _url;
        
        var theObj = this;
        var grid = this.el;
        
        var _start = 0;
        var _bbar = grid.getBottomToolbar();
        _start = (_bbar)?_bbar.cursor:0;
	    var sm = this.el.getSelectionModel(); 
        if(sm){
            sm.deselectRange(0,this.pageSize);
        }
        
        //-----------------------------------------------------------
        //-----------------------------------------------------------
        var paramsInfo = {method:"GET"};
        if(this.bbar==true){
            paramsInfo.start = 0;
            paramsInfo.limit = (this.pageSize)?this.pageSize:6;
        }
        
        var loadConfig = {
            params:paramsInfo,
            scope : grid,
            callback :function(){
                //debugger;
                var success = arguments[2];
                var _request = arguments[1];
                grid.loadMask.el.unmask(this.removeMask);
                if(grid.getBottomToolbar())
                    grid.getBottomToolbar().loading.enable();
                var results = arguments[0];
                //debugger;
                if(!success){
                    results =[];
                    if(_request.datasetFlag){
                        grid.getStore().removeAll();
                    }else{
                        Ext.Msg.show({
                            title: '系统信息',buttons: Ext.MessageBox.OK,icon: Ext.MessageBox.INFO,
                            msg: (_request.errorInfo)?_request.errorInfo:'网络异常！请刷新或检查网络！'
                        });
                    }
                }
                theObj.afterLoad(results);
            }
        };
                
        grid.getStore().proxy = new Ext.data.HttpProxy({url:_url});
        grid.getStore().load(loadConfig);
    },

    beforeLoad : function(){
        return true;
    },
    afterLoad : function(records){
    	//debugger;
    },

    removeAll : function(){
        this.el.getStore().removeAll();
    },
    
    setValueByDataIndex:function(row,dataIndex,value){
        var gridStore = this.el.getStore();           //获得表格对应的数据集
        gridStore.getAt(row).set(dataIndex,value);    //为指定行，指定字段赋值（自动刷新表格）
    },
    //=============================================================================================
    //=============================================================================================
    createGridByConfig : function(config){
        var field     = (config.field)?config.field:[];
        var col       = (config.col)?config.col:[];
        var dataArray = (config.dataArray)?config.dataArray:[];
        var id        = (config.id)?config.id:"";
        var others    = (config.others)?config.others:{};
          
        //----------------------------------------------------------------------
        //构造record的定义
        //----------------------------------------------------------------------
        var _cm = [];
        
        if(others.colNumber){
            if(this.colNumber) {
                _cm.push(new Ext.grid.RowNumberer());
            }
        }
        if(others.colCheckbox){
            
            var sFlag = (others.colCheckbox.singleSelect)?others.colCheckbox.singleSelect:false;
            
            var sm = null;
            if(sFlag) 
                sm = new Ext.grid.RadioSelectionModel({singleSelect:true});
            else 
                sm = new Ext.grid.CheckboxSelectionModel();
            _cm.push(sm);
        }
        _cm = _cm.concat(col);
        
        //----------------------------------------------------------------------
        //构造record的定义
        //----------------------------------------------------------------------
        var _ds = []; 
        if(id!="") _ds.push(id);
        for(var i=0;i<field.length;i++){
            var oDS = {
                name: field[i], 
                type: 'string'            
            };
            _ds.push(oDS);
        }

        for(var i=0;i<col.length;i++){
            var oDS = {
                name: col[i].dataIndex,
                type: 'string'            
            };
            _ds.push(oDS);
        }
        
        //----------------------------------------------------------------------
        //绑定数据
        //----------------------------------------------------------------------
        var newDS = new Ext.data.Store({
		    proxy: new Ext.data.PagingMemoryProxy(dataArray),
		    reader: new Ext.data.ArrayReader({}, _ds)
        });
                
        var newCM = new Ext.grid.ColumnModel(_cm);
        if(config.headers!=undefined)
            newCM.headers = config.headers;


        
        this.el.reconfigure(newDS,newCM);
        this.el.getStore().load({params:{start:0, limit:this.pageSize}});
        //this.el.getColumnModel().setConfig(_cm);
        this.el.getView().fitColumns(true,false);
        
    },
    
    reCreateGridByArray : function(recordDefine,colModel,dataArray){
        var _cm=[],_ds=[];
        
        for(var i=0;i<colModel.length;i++){
            var oCM = {
                id:'col_'+i,
                header: colModel[i],
                width: 100,  
                sortable: false, 
                dataIndex: 'data'+i,
                locked:false 
            };
            _cm.push(oCM);
            
            var oDS = {
                name: 'data'+i, 
                type: 'string'            
            };
            _ds.push(oDS);
        }
        
        var newDS = new Ext.data.Store({
		    proxy: new Ext.data.PagingMemoryProxy(dataArray),
		    reader: new Ext.data.ArrayReader({}, _ds)
        });
                
        var newCM = new Ext.grid.ColumnModel(_cm);
        
        this.el.reconfigure(newDS,newCM);
        this.el.getStore().load({params:{start:0, limit:this.pageSize}});
        //this.el.getColumnModel().setConfig(_cm);
        this.el.getView().fitColumns(true,false);
    },


    //=============================================================================================
    //=============================================================================================
    getRecord : function(row){
        var record = this.el.getStore().getAt(row);
        return record;
    },
    getRecordID : function(){
        var a = arguments;
        if(a.length==0) {alert("获取记录时，没有传入参数！");return;}
        
        var row = a[0];
        var field = (a.length>1)?a[1]:"id";
        
        var record = this.getRecord(row);
        if(record){
            var result = (record)?record.get(field):"";
            if(result){
                return result;
            }else{
                alert("没有找到指定行的ID，行序号="+row+"，字段="+field);
            }
        }else{
            alert("没有找到指定的行，行序号="+row);
        }
    },
    getFirstRowID : function(){
        return this.getRecordID(0);
    },
    canbeOperated : function(r){
        if(this.dataMode=="purview"){
            var _creator = r.get(this.creatorField);
            var _loginer = sc.getUser();

            _creator = (_creator=='')?_loginer:_creator;
            return (_creator==_loginer)?true:false;
        }
        else 
            return true;
                    
        /*if(this.dataMode=="purview")
            return (r.get(this.modeField)=="1")?true:false;
        else 
            return true;*/
    },
    getButtonIndexByText : function(text){
        for(var i=0,len=this.tbarButtons.length;i<len;i++){
            if(this.tbarButtons[i]["text"]==text) return i;
        }
        return -1;
    },
    getButton:function(key){
        var type =  typeof key;
        if(type=="string"){
            var index = this.getButtonIndexByText(key);
            if(index==-1) {
                //alert("没有找到符合条件的按钮！");
                return null;
            }
            var id = this.btIDPrefix+index;
            return this.el.getTopToolbar().items.get(id);
        }else if(type=="number"){
            key = (key==0)?0:key+1;
            return this.el.getTopToolbar().items.get(key);
        }else{
            alert("传递的参数错误！");
        }
        return null;
    },
    getLastSelected : function(){
	    var sm = this.el.getSelectionModel(); 
        if(sm.getLastSelected()){
            return sm.getLastSelected();
        }else{
            if(this.el.store.getAt(0)){
                return this.el.store.getAt(0);
            }else{
                return {get:function(){alert("没有找到被选择的记录！");return "";}};
            }
        }
        //return (sm.getLastSelected())?sm.getLastSelected():{get:function(){alert("没有找到被选择的记录！");return "";}};
    },
    getLastSelectedIndex : function(){
	    var sm = this.el.getSelectionModel(); 
        if(sm.getLastSelected()){
            var record = sm.getLastSelected();
            return this.el.store.indexOf(record);
        }else{
            return (this.el.store.getAt(0))?0:-1;
        }
    },
    
    selectRow : function(row){
        if(arguments.length==1){
            if(this.el.store.getAt(row))
                this.el.getSelectionModel().selectRow(row,false);
        }else if(arguments.length==2){
            if(this.el.store.getAt(row))
                this.el.getSelectionModel().selectRow(row,arguments[1]);
        }
    },

    selectRows : function(rows){
        this.el.getSelectionModel().selectRows(rows,false);
    },

    selectFirstRow : function(){
        if(this.el.getSelectionModel())
            this.el.getSelectionModel().selectFirstRow();
    },
    
    getSelections : function(){
        var a = arguments,sfield="",fn = null;
        if(a.length==0){
            //sfield = this.selectedField;
	        var sm = this.el.getSelectionModel(); 
	        var sa = sm.getSelections();
            var returnArray = [];
            for(var i=0;i<sa.length;i++){
                if(this.canbeOperated(sa[i])){
                    returnArray.push(sa[i]);
                }
            }
	        return returnArray;
        }
        else if(a.length==1){
            sfield = ""+a[0];
        }else if(a.length==2){
            sfield = ""+a[0];
            if(typeof a[1] =='function'){
                fn = a[1];
            }
        }else{
            return [];
        }

        var ra = [];
        var sm = this.el.getSelectionModel(); 
        var sa = sm.getSelections();
        for(var i=0;i<sa.length;i++){
            if(this.canbeOperated(sa[i])){
                if(fn!=null && fn!=undefined){
                    var flag = fn.call('',sa[i]);
                    if(flag)
                        ra.push(sa[i].get(sfield));
                }else{
                    ra.push(sa[i].get(sfield));
                }
                
            }
        }
        return ra;
    },
    
    setHeader : function(col,header){
        this.el.getColumnModel().setColumnHeader(col,header);
    },
    setHeaders : function(beginCol,endCol,headers){
        var headerModel = this.el.getColumnModel();

        for(var i=beginCol;i<=endCol;i++){
            headerModel.setColumnHeader(i,headers[i-beginCol]);
        }
    },
    getCount : function(){
        return this.el.store.getCount();
    },
    
    setFieldValue : function(row,col,value){
        var cell = this.el.getView().getCell(row,col);
        cell.children[0].innerText = value;
        
        if(arguments.length==4&&arguments[3]===true){
            var cm = this.el.getColumnModel();
            var _name = cm.config[col].dataIndex;
            this.el.store.getAt(row).editing = true;
            this.el.store.getAt(row).set(_name,value);
        }
    },
    
    //=============================================================================================
    //=============================================================================================
    hideCols : function(cols){
        
        var hideInfo = (cols.length)?cols:[];
        var gridCM = this.el.getColumnModel();
        for(var i=0;i<hideInfo.length;i++)
            gridCM.setHidden(hideInfo[i],true);
        
        //this.el.getView().fitColumns(true,false);
        //this.el.getView().refresh();
    },
    showCols : function(cols){
        var hideInfo = (cols.length)?cols:[];
        var gridCM = this.el.getColumnModel();
        for(var i=0;i<hideInfo.length;i++)
            gridCM.setHidden(hideInfo[i],false);
    },
    setTitle : function(title){
        this.el.setTitle(title);
    },
    //=============================================================================================
    //=============================================================================================
    getFieldsFromCol : function(c){
        var fs = [];
        for(var i=0;i<c.length;i++){
            var haveFlag = this.checkHave(c[i]["dataIndex"],fs);
            if(!haveFlag) fs.push(c[i]["dataIndex"]);
        }
        return fs;
    },
    checkHave : function(f,a){
        var sa = ","+a.join(",")+",";
        return (sa.indexOf(","+f+",")==-1)?false:true;
    },
    isAddField : function(f,a){
        for(var i=0;i<a.length;i++){
            if((typeof a[i]) =="object"){
                if(a[i].name==f) return true;
            }else{
                if(a[i]==f) return true;
            }
        }
        return false;
    },
    getRenderer4Check : function(v){
        return (v=="1")?'<div class=\"x-grid3-row-checker\">&#160;</div>':"";
    },
    getRenderer4Radio : function(v){
        return (v=="1")?'<div class=\"x-grid3-row-radio\">&#160;</div>':"";
    },

    setTextByDataIndex : function(row,col,text){
        var cell = this.el.getView().getCell(row,col);
        cell.children[0].innerText = text;
    },

    getTextByDataIndex : function(row,col){
        var cell = this.el.getView().getCell(row,col);
        return cell.children[0].innerText;
    },


    createWidgetElement:function(){
        //debugger;
        var r = this.bindRelation;
        if(r && r.col){
            var theObj = this;
            var fields=[],rConfig = [],addFields= (r.field)?r.field:[]; 
            var _root= r.root, _id=(r.id)?r.id:"id", pField= (r.pField)?r.pField:this.modeField;
            var creatorField =(r.creator)?r.creator:this.creatorField;
            this.creatorField = creatorField;

            this.smRowspan  = r.smRowspan;
            this.usePlugins = r.usePlugins;
            this.headers    = r.headers;

            //-----------------------------------------------------------------------------------------
            //-----------------------------------------------------------------------------------------
            fields = this.getFieldsFromCol(r.col); 
            if(!this.checkHave(creatorField,fields)) fields.push(creatorField);
            if(!this.checkHave(pField,fields))       fields.push(pField);
            if(!this.checkHave(_id,fields))          fields.push(_id);
            
            for(var i=0,len=addFields.length;i<len;i++){
                if((typeof addFields[i]) =="object") rConfig.push(addFields[i]);
                else rConfig.push({name:addFields[i]});
            }
            for(var i=0,len=fields.length;i<len;i++){
                if(this.isAddField(fields[i],addFields)){continue;}
                rConfig.push({name:fields[i]});
            }

            var _record = Ext.data.Record.create(rConfig);
            var _reader = new Ext.data.JsonReader({
                    root: _root,
                    id:_id,
                    totalProperty: "dataset.totalRecords",
                    successProperty:"response"
                }, _record
            );
            
            var dataStore = new Ext.data.Store({url: theObj.url,reader: _reader});
            
            //-----------------------------------------------------------------------------------------
            var loginer = sc.getUser();
            var creatorField = this.creatorField;

            var getRenderer4Check = null;
            var getRenderer4Radio = null;

            //-----------------------------------------------------------------------------------------
            //-----------------------------------------------------------------------------------------
            if(this.checkboxRenderer!=undefined){
                var getRenderer4Check = this.checkboxRenderer;
                var getRenderer4Radio = this.checkboxRenderer;
            }else{
                eval("getRenderer4Check = function(val,p,r){\n"
                +" var recordCreator = r.get('"+creatorField+"');\n"
                +" recordCreator = (recordCreator=='')?'"+loginer+"':recordCreator;"
                +"return (recordCreator!='"+loginer+"')?'':\"<div class='x-grid3-row-checker'>&#160;</div>"
                +"\";}");
    
                eval("getRenderer4Radio = function(val,p,r){\n"
                +" var recordCreator = r.get('"+creatorField+"');\n"
                +" recordCreator = (recordCreator=='')?'"+loginer+"':recordCreator;"
                +"return (recordCreator!='"+loginer+"')?'':\"<div class='x-grid3-row-radio'>&#160;</div>"
                +"\";}");
            }
            
            //-----------------------------------------------------------------------------------------
            var newCMDefine = [];
            if(this.colNumber) {
                newCMDefine.push(new Ext.grid.RowNumberer());
            }
            if(this.colCheckbox) {
                var sm = null;
                if(this.singleSelect) sm = new Ext.grid.RadioSelectionModel({singleSelect:true});
                else sm = new Ext.grid.CheckboxSelectionModel();
                    
                if(this.dataMode=="purview"){
                    sm.dataIndex = this.modeField;
                    sm.renderer  = (this.singleSelect)?getRenderer4Radio:getRenderer4Check;
                }
                if(this.smRowspan) sm.rowspan = this.smRowspan;
                newCMDefine.push(sm);
            }

            for(var i=0;i<r.col.length;i++){
                r.col[i]["sortable"] = (r.col[i]["sortable"]!=undefined)?r.col[i]["sortable"]:true;
                r.col[i]["locked"] = false;
                r.col[i]["id"] = "col_"+i;
                
                r.col[i]["css"] = "border-right:1px #EDEDED solid;";
                r.col[i]["align"] =(r.col[i]["align"]!=undefined)?r.col[i]["align"]:"center";
                
                if(r.col[i]["actionText"]){
                    var text = r.col[i]["actionText"];
                    var loginer = sc.getUser();
                    var creatorField = this.creatorField;
                    if(this.dataMode=="purview"){
                        eval("var tf = function(val,p,r){\n"
                        +" var recordCreator = r.get('"+creatorField+"');\n"
                        +" recordCreator = (recordCreator=='')?'"+loginer+"':recordCreator;"
                        +" var outText = ('"+text+"'=='打印')?'打印':'查看';"
                        +"return (recordCreator!='"+loginer+"')?\"<span style='cursor:hand;color:#000066;'>\"+outText+\"</span>\":\"<span style='cursor:hand;color:#000066;'>"
                        +text
                        +"</span>\";}");
                    }else{
                        eval("var tf = function(val,p,r){return \"<span style='cursor:hand;color:#000066;'>"+text+"</span>\";}");
                    }
                    if(r.col[i]["renderer"])
                   	    ;
                    else
                    	r.col[i]["renderer"] = tf;
                    
                    r.col[i]["align"] = "center";
                    r.col[i]["fixed"] = true;
                    r.col[i]["sortable"] = false;
                }
                newCMDefine.push(r.col[i]);
            }
            //debugger;
            var newCM = new Ext.grid.ColumnModel(newCMDefine);
            //debugger;
            
            if(this.usePlugins!=undefined){
                var tmpArray = [];
                if(this.colNumber)
                    tmpArray.push({header:"", rowspan:2});
                    
                if(this.colCheckbox){
                     tmpArray.push(sm);
                     this.headers[0] = tmpArray.concat(this.headers[0]);
                     //this.headers[0].push(sm);
                }
                newCM.headers = this.headers;
            }
            
            //-----------------------------------------------------------------------------------------
            //-----------------------------------------------------------------------------------------
            var sm = null;
            if(this.singleSelect) sm = new Ext.grid.RadioSelectionModel({singleSelect:true});
            else sm = new Ext.grid.CheckboxSelectionModel();
                
            if(this.dataMode=="purview"){
                sm.dataIndex = this.modeField;
                sm.renderer  = (this.singleSelect)?getRenderer4Radio:getRenderer4Check;
            }
            if(this.smRowspan) sm.rowspan = this.smRowspan;
            
            //sm =  new Ext.grid.CellSelectionModel();
            
            var gConfig = {
                stripeRows:true,viewConfig: {autoFill:true},
                loadMask: true,store:dataStore,cm:newCM,sm:sm,
                //width:this.width,
                //height:this.height,
                animCollapse:false/*,
                renderTo: this.getOCD()(*/
            };
            
            if(this.autoFill!=undefined){
                gConfig.viewConfig.autoFill = this.autoFill;
            }
            
            if(this.usePlugins!=undefined){
                ;
            }else{
                gConfig.width = this.width;
                gConfig.height = this.height;
                gConfig.renderTo = this.getOCD();
            }
            
            if(this.showTitle){
                gConfig.title = this.title;gConfig.iconCls = "icon-grid";
            }
            if(this.tbar){
                var index=0;
                for(var i=0;i<this.tbar.length;i++){
                    if(this.tbar[i]=="-") continue;
                    this.tbar[i].id=this.btIDPrefix+index;
                    index++;
                    if(this.tbar[i].text=="新增") this.tbar[i].iconCls="grid_add";
                    else if(this.tbar[i].text=="删除") this.tbar[i].iconCls="grid_del";
                    else this.tbar[i].iconCls="grid_bt";
                    this.tbarButtons.push({text:this.tbar[i].text});
                    
                    if(sc.isList()){
                        if(sc.runMode!=="debug") {
                            if(sc.haveOperFun(this.tbar[i].text,this.title)==false){
                                this.tbar[i].disabled=true;
                                this.tbar[i].hidden=true;
                            }
                        }
                    }
                }
                gConfig.tbar = this.tbar;
            }
            if(this.collapsible){
                gConfig.collapsible = this.collapsible;
            }
            
            if(this.bbar){
    	        gConfig.bbar= new Ext.PagingToolbar({
                    pageSize: (this.pageSize)?this.pageSize:6,
                    store: dataStore,
                    beforePageText:'第',
                    afterPageText:'页，共 {0}页',
                    displayMsg: '显示第 {0} - {1} 条，共 {2} 条',
                    emptyMsg: "没有记录",
                    displayInfo: true
                })
            }
            if(this.usePlugins!=undefined){
                gConfig.plugins= new Ext.ux.plugins.XGrid();
            }
            
            var grid = new Ext.grid.GridPanel(gConfig);

            //-----------------------------------------------------------
            //-----------------------------------------------------------
            var paramsInfo = {method:"GET"};
            if(this.bbar==true){
                paramsInfo.start = 0;
                paramsInfo.limit = (this.pageSize)?this.pageSize:6;
            }

            var loadConfig = {
                params:paramsInfo,
                scope : grid,
                callback :function(){
                    //debugger;
                    var success  = arguments[2];
                    var _request = arguments[1];
                    if(!success){
                        if(_request.datasetFlag){
                            grid.getStore().removeAll();
                        }else{
                            Ext.Msg.show({
                                title: '系统信息',buttons: Ext.MessageBox.OK,icon: Ext.MessageBox.INFO,
                                msg: (_request.errorInfo)?_request.errorInfo:'网络异常！请刷新或检查网络！'
                            });
                        }
                    }
                    //theObj.selectFirstRow();                        
                    theObj.afterLoad();
                }
            };
            if(theObj.url!=""){
                grid.getStore().load(loadConfig);
            }
            this.el  = grid;
            
            if(this.usePlugins!=undefined){
                grid.render(this.OCD.id);
                grid.reconfigure(grid.store, grid.getColumnModel());
            }
            
            this.el.setWidth(this.OCD.offsetWidth);
            //this.el.setHeight(this.OCD.offsetHeight);
            //this.el.getView().refresh();
        }
        
        //---------------------------------------------------------------------------------------------


        //ds.load({params:{start:0, limit:this.pageSize}});    
        
        //---------------------------------------------------------------------------------------------
        
    }

    
});


















Sail.widget.ext.hidden = function(config){
    Sail.apply(this, config);
    Sail.widget.ext.superclass.constructor.call(this);
    this.value;
}
Sail.extend(Sail.widget.ext.hidden,Sail.widget.ext,{
    
    getValue : function(){
        return this.value;
    },
    setValue : function(v){
        this.value=v;
    },
    enable : function(){return;},
    disable : function(){return;},
	
    createWidgetElement:function(){
        
        var containerDiv = this.getOCD();                   //获得组件容器层
        //---------------------------------------------------------------------------------------------
        var titleDiv = document.createElement( "DIV" );     //创建标题容器
        containerDiv.appendChild( titleDiv );               //添加到包裹容器

        Sail.apply(titleDiv,{innerText:(this.title=="")?"":this.title+"：",align:"left",noWrap:true});  //定义对象
        Sail.apply(titleDiv.style,{color:"#000000",border:"0 #ababab solid",top:4,left:0,cursor:"default",position:"absolute",overflow:"hidden",marginLeft:3});
        this.hide();
        //---------------------------------------------------------------------------------------------
        //---------------------------------------------------------------------------------------------
        this.titleWidth = 0;
        this.titleDiv = titleDiv;
        this.inputDiv = titleDiv;
        this.el  = titleDiv;
    }
});




/**************************************************************************************************
* 对象： Sail.widget.ext.input
* 说明： 
*
**************************************************************************************************/
Sail.widget.ext.input = function(config){
    Sail.apply(this, config);
    Sail.widget.ext.superclass.constructor.call(this);
}
Sail.extend(Sail.widget.ext.input,Sail.widget.ext,{
    
    getValue : function(){
        return this.el.getValue();
    },
    setValue : function(v){
        this.el.setValue(v);
    },
    
    enable : function(){
        this.titleDiv.style.color = "#000000";
        this.el.enable();
    },
    disable : function(){
        this.titleDiv.style.color = "#a0a0a0";
        this.el.disable();
    },

    createWidgetElement:function(){

        var containerDiv = this.getOCD();                   //获得组件容器层
        //---------------------------------------------------------------------------------------------
        var titleDiv = document.createElement( "DIV" );     //创建标题容器
        containerDiv.appendChild( titleDiv );               //添加到包裹容器

        var _innerText = (this.title=="")?"":this.title+"：";
        var _tmpText = this.mustMark+((_innerText.indexOf('*')!=-1)?_innerText.replace("*",''):_innerText);
        var _innerHTML  =(this.allowBlank!=undefined && this.allowBlank==false)?_tmpText:((_innerText.indexOf('*')!=-1)?_tmpText:_innerText);
        Sail.apply(titleDiv,{innerHTML:_innerHTML,align:"left",noWrap:true});  //定义对象
        
        Sail.apply(titleDiv.style,{color:"#000000",border:"0 #ababab solid",top:4,left:0,cursor:"default",position:"absolute",overflow:"hidden",marginLeft:3});
        this.titleWidth = titleDiv.offsetWidth;             //获得标题实际尺寸
        
        //-----------------------------------------------------------------------------------------
        //定义 数据层 （需要根据折行与否计算位置及尺寸）
        //-----------------------------------------------------------------------------------------
        var inputDivLeft   = this.titleWidth + 4;;
        var inputDivWidth  = this.width - this.titleWidth -4;
        var inputDivHeight = 22;
        this.boxWidth = inputDivWidth;
        
        var inputDiv = document.createElement( "DIV" );     //创建值容器
        containerDiv.appendChild( inputDiv );               //添加到包裹容器
        Sail.apply(inputDiv.style,{left:inputDivLeft,top:0,width:inputDivWidth,height:22,position:"absolute",overflow:"hidden"});
        
        //---------------------------------------------------------------------------------------------
        var _config ={width:inputDivWidth,renderTo:inputDiv};

        if(this.readOnly!=undefined) _config.readOnly      = this.readOnly;
        if(this.minLength!=undefined) _config.minLength    = this.minLength;
        if(this.maxLength!=undefined) _config.maxLength    = this.maxLength;
        if(this.allowBlank!=undefined) _config.allowBlank  = this.allowBlank;
        if(this.inputType!=undefined)   _config.inputType= this.inputType;

        var _input = new Ext.form.TextField(_config);        

        if(this.maxLength) _input.el.dom.maxLength = this.maxLength;
        //---------------------------------------------------------------------------------------------
        this.titleDiv = titleDiv;
        this.inputDiv = inputDiv;
        this.el  = _input;
    }
});


Sail.widget.ext.numInput = function(config){
    Sail.apply(this, config);
    Sail.widget.ext.superclass.constructor.call(this);
}
Sail.extend(Sail.widget.ext.numInput,Sail.widget.ext,{
    
    getValue : function(){
        return this.el.getValue();
    },
    setValue : function(v){
        this.el.setValue(v);
    },
    
    enable : function(){
        this.titleDiv.style.color = "#000000";
        this.el.enable();
    },
    disable : function(){
        this.titleDiv.style.color = "#a0a0a0";
        this.el.disable();
    },
    getCheckInfo : function(){
        var ci = {};
        
        if(this.minLength !=undefined) ci.minLength    = this.minLength;
        if(this.maxLength !=undefined) ci.maxLength    = this.maxLength;
        if(this.minValue  !=undefined) ci.minValue     = this.minValue;
        if(this.maxValue  !=undefined) ci.maxValue     = this.maxValue;
        if(this.allowBlank !=undefined) ci.allowBlank  = this.allowBlank;
        if(this.allowDecimals !=undefined) ci.allowDecimals       = this.allowDecimals;
        if(this.allowNegative !=undefined) ci.allowNegative       = this.allowNegative;
        if(this.decimalPrecision !=undefined) ci.decimalPrecision = this.decimalPrecision;
        return ci;
    },

    createWidgetElement:function(){

        var containerDiv = this.getOCD();                   //获得组件容器层
        //---------------------------------------------------------------------------------------------
        var titleDiv = document.createElement( "DIV" );     //创建标题容器
        containerDiv.appendChild( titleDiv );               //添加到包裹容器

        var _innerText = (this.title=="")?"":this.title+"：";
        var _tmpText = this.mustMark+((_innerText.indexOf('*')!=-1)?_innerText.replace("*",''):_innerText);
        var _innerHTML  =(this.allowBlank!=undefined && this.allowBlank==false)?_tmpText:((_innerText.indexOf('*')!=-1)?_tmpText:_innerText);
        Sail.apply(titleDiv,{innerHTML:_innerHTML,align:"left",noWrap:true});  //定义对象
        //Sail.apply(titleDiv,{innerText:(this.title=="")?"":this.title+"：",align:"left",noWrap:true});  //定义对象

        Sail.apply(titleDiv.style,{color:"#000000",border:"0 #ababab solid",top:4,left:0,cursor:"default",position:"absolute",overflow:"hidden",marginLeft:3});
        this.titleWidth = titleDiv.offsetWidth;             //获得标题实际尺寸
        
        //-----------------------------------------------------------------------------------------
        //定义 数据层 （需要根据折行与否计算位置及尺寸）
        //-----------------------------------------------------------------------------------------
        var inputDivLeft   = this.titleWidth + 4;;
        var inputDivWidth  = this.width - this.titleWidth -4;
        var inputDivHeight = 22;
        this.boxWidth = inputDivWidth;        
        
        var inputDiv = document.createElement( "DIV" );     //创建值容器
        containerDiv.appendChild( inputDiv );               //添加到包裹容器
        Sail.apply(inputDiv.style,{left:inputDivLeft,top:0,width:inputDivWidth,height:22,position:"absolute",overflow:"hidden"});

        //---------------------------------------------------------------------------------------------
        var _config ={width:inputDivWidth,renderTo:inputDiv};

        if(this.readOnly !=undefined)  _config.readOnly     = this.readOnly;
        if(this.minLength !=undefined) _config.minLength    = this.minLength;
        if(this.maxLength !=undefined) _config.maxLength    = this.maxLength;
        if(this.minValue  !=undefined) _config.minValue     = this.minValue;
        if(this.maxValue  !=undefined) _config.maxValue     = this.maxValue;

        if(this.allowBlank !=undefined)         _config.allowBlank      = this.allowBlank;
        if(this.allowDecimals !=undefined)      _config.allowDecimals   = this.allowDecimals;
        if(this.allowNegative !=undefined)      _config.allowNegative   = this.allowNegative;
        if(this.decimalPrecision !=undefined)   _config.decimalPrecision= this.decimalPrecision;
        
        var _input = new Ext.form.NumberField(_config);        

        if(this.maxLength!=undefined) _input.el.dom.maxLength = this.maxLength;
        
        var theObj = this;
        _input.on('specialkey', function(f, e){
            if(e.getKey()==e.ENTER){
                theObj.enterFunc.call(e,f.getValue(),f);
                //e.keyCode = e.TAB;
            }
        });

        
        //var _input = new Ext.form.NumberField({width:inputDivWidth,renderTo:inputDiv});        
        //---------------------------------------------------------------------------------------------
        this.titleDiv = titleDiv;
        this.inputDiv = inputDiv;
        
        this.el  = _input;
    }
});



Sail.widget.ext.timeInput = function(config){
    Sail.apply(this, config);
    Sail.widget.ext.superclass.constructor.call(this);
}
Sail.extend(Sail.widget.ext.timeInput,Sail.widget.ext,{
    
    getValue : function(){
        return this.el.getValue();
    },
    setValue : function(v){
        this.el.setValue(v);
    },
    
    enable : function(){
        this.titleDiv.style.color = "#000000";
        this.el.enable();
    },
    disable : function(){
        this.titleDiv.style.color = "#a0a0a0";
        this.el.disable();
    },
    getCheckInfo : function(){
        var ci = {};
        
        if(this.minLength !=undefined) ci.minLength    = this.minLength;
        if(this.maxLength !=undefined) ci.maxLength    = this.maxLength;
        if(this.minValue  !=undefined) ci.minValue     = this.minValue;
        if(this.maxValue  !=undefined) ci.maxValue     = this.maxValue;
        if(this.allowBlank !=undefined) ci.allowBlank  = this.allowBlank;
        if(this.allowDecimals !=undefined) ci.allowDecimals       = this.allowDecimals;
        if(this.allowNegative !=undefined) ci.allowNegative       = this.allowNegative;
        if(this.decimalPrecision !=undefined) ci.decimalPrecision = this.decimalPrecision;
        return ci;
    },

    createWidgetElement:function(){

        var containerDiv = this.getOCD();                   //获得组件容器层
        //---------------------------------------------------------------------------------------------
        var titleDiv = document.createElement( "DIV" );     //创建标题容器
        containerDiv.appendChild( titleDiv );               //添加到包裹容器

        var _innerText = (this.title=="")?"":this.title+"：";
        var _tmpText = this.mustMark+((_innerText.indexOf('*')!=-1)?_innerText.replace("*",''):_innerText);
        var _innerHTML  =(this.allowBlank!=undefined && this.allowBlank==false)?_tmpText:((_innerText.indexOf('*')!=-1)?_tmpText:_innerText);
        Sail.apply(titleDiv,{innerHTML:_innerHTML,align:"left",noWrap:true});  //定义对象
        //Sail.apply(titleDiv,{innerText:(this.title=="")?"":this.title+"：",align:"left",noWrap:true});  //定义对象

        Sail.apply(titleDiv.style,{color:"#000000",border:"0 #ababab solid",top:4,left:0,cursor:"default",position:"absolute",overflow:"hidden",marginLeft:3});
        this.titleWidth = titleDiv.offsetWidth;             //获得标题实际尺寸
        
        //-----------------------------------------------------------------------------------------
        //定义 数据层 （需要根据折行与否计算位置及尺寸）
        //-----------------------------------------------------------------------------------------
        var inputDivLeft   = this.titleWidth + 4;;
        var inputDivWidth  = this.width - this.titleWidth -4;
        var inputDivHeight = 22;
        this.boxWidth = inputDivWidth;        
        
        var inputDiv = document.createElement( "DIV" );     //创建值容器
        containerDiv.appendChild( inputDiv );               //添加到包裹容器
        Sail.apply(inputDiv.style,{left:inputDivLeft,top:0,width:inputDivWidth,height:22,position:"absolute",overflow:"hidden"});

        //---------------------------------------------------------------------------------------------
        var _config ={width:inputDivWidth,renderTo:inputDiv};
        this.maxLength = 5;
        
        if(this.readOnly !=undefined)  _config.readOnly     = this.readOnly;
        if(this.minLength !=undefined) _config.minLength    = this.minLength;
        if(this.maxLength !=undefined) _config.maxLength    = this.maxLength;
        if(this.minValue  !=undefined) _config.minValue     = this.minValue;
        if(this.maxValue  !=undefined) _config.maxValue     = this.maxValue;
        if(this.allowBlank !=undefined)_config.allowBlank   = this.allowBlank;

        var _input = new Ext.form.timeInput(_config);        

        if(this.maxLength!=undefined) _input.el.dom.maxLength = this.maxLength;

        //var _input = new Ext.form.NumberField({width:inputDivWidth,renderTo:inputDiv});        
        //---------------------------------------------------------------------------------------------
        this.titleDiv = titleDiv;
        this.inputDiv = inputDiv;
        
        this.el  = _input;
    }
});


/**************************************************************************************************
* 对象： Sail.widget.ext.input
* 说明： 
*
**************************************************************************************************/
Sail.widget.ext.checkInput = function(config){
    Sail.apply(this, config);
    Sail.widget.ext.superclass.constructor.call(this);
    
    this.checkbox = null;
}
Sail.extend(Sail.widget.ext.checkInput,Sail.widget.ext,{
    destroy: function(){
        this.OCD.removeNode(true);
        this.checkbox.destroy();
        this.el.destroy();
        
        var index = sc.getWidgetIndexByID(this.id);
        sc.removeEl(index);
    },

    getValue : function(k){
        if(k==0)
            return (this.checkbox.getValue())?"1":"0";
        else if(k==1)
            return this.el.getValue();
        else{
            return {check:(this.checkbox.getValue())?"1":"0",text:this.el.getValue()};
        }
    },
    setValue : function(v){
        this.checkbox.setValue(v[0]=='1'?true:false);
        this.el.setValue(v[1]);
    },
    
    enable : function(){
        this.titleDiv.style.color = "#000000";
        this.el.enable();
    },
    disable : function(){
        this.titleDiv.style.color = "#a0a0a0";
        this.el.disable();
    },

    bindData : function(relation,dataArray){
        //debugger;
        var a = arguments;
        var d = (a.length==1)?a[0]:a[1];
        
        this.checkbox.setValue((d[0]=="0")?false:true);
        this.setValue(d[1]);
    },

    createWidgetElement:function(){

        var containerDiv = this.getOCD();                   //获得组件容器层
        //---------------------------------------------------------------------------------------------
        var titleDiv = document.createElement( "DIV" );     //创建标题容器
        containerDiv.appendChild( titleDiv );               //添加到包裹容器

        var _innerText = (this.title=="")?"":this.title+"：";
        var _tmpText = this.mustMark+((_innerText.indexOf('*')!=-1)?_innerText.replace("*",''):_innerText);
        var _innerHTML  =(this.allowBlank!=undefined && this.allowBlank==false)?_tmpText:((_innerText.indexOf('*')!=-1)?_tmpText:_innerText);
        Sail.apply(titleDiv,{innerHTML:_innerHTML,align:"left",noWrap:true});  //定义对象

        //Sail.apply(titleDiv,{innerText:(this.title=="")?"":this.title+"：",align:"left",noWrap:true});  //定义对象
        Sail.apply(titleDiv.style,{color:"#000000",border:"0 #ababab solid",top:4,left:0,cursor:"default",position:"absolute",overflow:"hidden",marginLeft:3});
        this.titleWidth = titleDiv.offsetWidth;             //获得标题实际尺寸
        
        //-----------------------------------------------------------------------------------------
        //定义 数据层 （需要根据折行与否计算位置及尺寸）
        //-----------------------------------------------------------------------------------------
        var inputDivLeft   = this.titleWidth + 4;;
        var inputDivWidth  = this.width - this.titleWidth -4;
        var inputDivHeight = 22;
        
        var inputDiv1 = document.createElement( "DIV" );     //创建值容器
        containerDiv.appendChild( inputDiv1 );               //添加到包裹容器
        Sail.apply(inputDiv1.style,{left:inputDivLeft,top:4,width:22,height:22,position:"absolute",overflow:"hidden"});
        var _check = new Ext.form.Checkbox({
            boxLabel : "",
            renderTo:inputDiv1
        });        
        this.checkbox = _check;
        
        var inputDiv2 = document.createElement( "DIV" );     //创建值容器
        containerDiv.appendChild( inputDiv2 );               //添加到包裹容器

        Sail.apply(inputDiv2.style,{left:inputDivLeft+22,top:0,width:inputDivWidth-22,height:22,position:"absolute",overflow:"hidden"});
        var txtConfig = {
            width:inputDivWidth-22,
            renderTo:inputDiv2
        };
        if(this.readOnly!=undefined) txtConfig.readOnly = this.readOnly;
        
        if(this.inputType === 'number')
            var _input = new Ext.form.NumberField(txtConfig);
        else
            var _input = new Ext.form.TextField(txtConfig);
        //---------------------------------------------------------------------------------------------
        if(this.value!=undefined) {
            _check.setValue((this.value[0]=="0")?false:true);
            _input.setValue(this.value[1]);
        }
        
        this.titleDiv = titleDiv;
        this.el  = _input;
    }
});


/**************************************************************************************************
* 对象： Sail.widget.ext.input
* 说明： 
*
**************************************************************************************************/
Sail.widget.ext.combSelectField = function(config){
    Sail.apply(this, config);
    Sail.widget.ext.superclass.constructor.call(this);
    
    this.el_combox      = null;
    this.el_selectField = null;
}
Sail.extend(Sail.widget.ext.combSelectField,Sail.widget.ext,{

    createCombox : function(containerDiv,_width){
        var _fields = [];
        var _textField =(this.fieldText)?this.fieldText:"text";
        var _valueField=(this.fieldValue)?this.fieldValue:"value";
        _fields.push(_textField);
        _fields.push(_valueField);
        
        this.fieldText = _textField;
        this.fieldValue = _valueField;
        
        var store = null;
        if(this.url && this.url!=""){
            store = new Ext.data.Store({
    	        proxy: new Ext.data.HttpProxy({url: this.url,method:"POST"}),
    	        reader: new Ext.data.JsonReader({root: this.root}, _fields)
            });

            store.load();
            store.on("datachanged",function(s){
                var _record = Ext.data.Record.create([
                    {name:_textField,  type:"string"},
                    {name:_valueField, type:"string"}
                ]);
                var cd={};
                cd[_textField]="未选择...";
                cd[_valueField]="";
                var p = new _record(cd);
                s.insert(0,p);
            })
            
        }
        else
            store = new Ext.data.SimpleStore({fields:(this.fields)?this.fields:[],data : (this.dataArray)?this.dataArray:[]});

        
        this.el_combox = new Ext.form.ComboBox({
            readOnly:true,
            store: store,
            displayField:_textField,
            name:_textField,
            valueField:_valueField,
            typeAhead: true,
            mode: 'local',
            triggerAction: 'all',
            emptyText:'未选择...',
            selectOnFocus:true,
            renderTo: containerDiv    
        });

        this.el_combox.setWidth(_width);     
        if(this.disabled) this.el_combox.disable();
    },
    
    createSelectField : function(containerDiv,_width){
        this.el = new Ext.form.SelectField({
            allowBlank : true,
            blankText : "未选择...",
            width : _width,
            openUrl : this.openUrl,
            openFn  : this.openFn,
            showValue : (this.text)?this.text:"text",
            renderTo: containerDiv
        });
        
        if(this.disabled) this.el_selectField.disable();
    },
    
    createWidgetElement:function(){

        var containerDiv = this.getOCD();                   //获得组件容器层
        //---------------------------------------------------------------------------------------------
        var titleDiv = document.createElement( "DIV" );     //创建标题容器
        containerDiv.appendChild( titleDiv );               //添加到包裹容器

        Sail.apply(titleDiv,{innerText:(this.title=="")?"":this.title+"：",align:"left",noWrap:true});  //定义对象
        Sail.apply(titleDiv.style,{color:"#000000",border:"0 #ababab solid",top:4,left:0,cursor:"default",position:"absolute",overflow:"hidden",marginLeft:3});
        this.titleWidth = titleDiv.offsetWidth;             //获得标题实际尺寸
        
        //-----------------------------------------------------------------------------------------
        //定义 数据层 （需要根据折行与否计算位置及尺寸）
        //-----------------------------------------------------------------------------------------
        var inputDivLeft   = this.titleWidth + 4;;
        var inputDivWidth  = this.width - this.titleWidth -4;
        var inputDivHeight = 22;
        
        //-----------------------------------------------------------------------------------------
        var div_combox = document.createElement( "DIV" );     //创建值容器
        containerDiv.appendChild( div_combox);               //添加到包裹容器
        Sail.apply(div_combox.style,{left:inputDivLeft,top:4,width:22,height:22,position:"absolute",overflow:"hidden"});
        var div_combox_width = inputDivWidth/2;
        
        this.createCombox(div_combox,div_combox_width);

        
        //-----------------------------------------------------------------------------------------
        var div_selectField = document.createElement( "DIV" );     //创建值容器
        containerDiv.appendChild(div_selectField);               //添加到包裹容器
        Sail.apply(div_selectField.style,{left:inputDivLeft+22,top:0,width:inputDivWidth-22,height:22,position:"absolute",overflow:"hidden"});

        var div_selectField_width = inputDivWidth/2;
        this.createSelectField(div_selectField,div_selectField_width);
        
        //---------------------------------------------------------------------------------------------
        this.titleDiv = titleDiv;
    }
});


/**************************************************************************************************
* 对象： Sail.widget.ext.selectField
* 说明： Ext.form.selectField
*
**************************************************************************************************/
Sail.widget.ext.selectField = function(config){
    
    Sail.apply(this, config);
    Sail.widget.ext.superclass.constructor.call(this);
    
}

Sail.extend(Sail.widget.ext.selectField,Sail.widget.ext,{
    
    getValue : function(){
        //return this.el.getValue();
        var a = arguments;
        if(a.length==0) return this.el.getDataObj((this.value)?this.value:"id");
        
        if(a[0]==0)
            return this.el.getDataObj((this.value)?this.value:"id");
        else 
            return this.getText();
    },
    getText : function(){
        return this.el.getDataObj((this.text)?this.text:"text");
    },
    
    bindData : function(){
        //debugger;
        var a = arguments;
        var d = (a.length==1)?a[0]:a[1];
        this.setDataObj(d);
    },
    setDataObj : function(d){
        var _text  = (this.text)?this.text:"text";
        var _value = (this.value)?this.value:"id";
        
        
        var dataObj = {};
        try{
            dataObj[_value] = d[0];
            dataObj[_text] = d[1];
            
            this.el.setDataObj(dataObj);
            this.setValue(d[1]);
        }catch(e){
            Ext.Msg.alert('提示：', '在为selectField赋值时，发生异常！'+e.message); 
        }
    },
    
    setValue : function(v){
        this.el.setValue(v);
    },
    getData : function(){
        return this.el.getDataObj();
    },
    enable : function(){
        this.el.enable();
    },
    disable : function(){
        this.el.disable();
    },
    
    changeFunc : function(){
        var a = arguments;
        if(a.length==0){this.setNull();return;}
        
        this.el.enable();
        var newConfig = {};
        
        if(a.length==1){
            var config = a[0];
            if((typeof config ) =="object"){
                Ext.apply(newConfig,config);
            }else{
                newConfig.openFn=config;
            }
        }
        
        if(a.length==2){
            var data = a[1];
            var config = a[0];
            
            if((typeof config ) =="object"){
                if(config.openFn){
                    if(data instanceof Array){
                        for(var i=0,len=data.length;i<len;i++){
                            config.openFn = config.openFn.replace("{"+i+"}",data[i]);
                        }
                    }else{
                        config.openFn = config.openFn.replace("{0}",data);
                    }
                }
                Ext.apply(newConfig,config);
            }else{
                if(data instanceof Array){
                    for(var i=0,len=data.length;i<len;i++){
                        config = config.replace("{"+i+"}",data[i]);
                    }
                }else{
                    config = config.replace("{0}",data);
                }
                newConfig.openFn=config;
            }
        }
        
        if(this.el.openFn!="" && newConfig.openFn!=this.el.openFn)
            this.el.setValue("");

        Ext.apply(this.el,newConfig);
        
    },
    setNull : function(){
        this.el.setValue("");
        this.el.openFn  ="";
        this.el.openUrl ="";
        this.el.disable();
    },
    
    //=================================================================================================
    //方法： createWidgetElement
    //说明： 在设计窗口中创建组件本身
    //=================================================================================================
    createWidgetElement:function(){
        
        var containerDiv = this.getOCD();               //获得组件容器层
        
        //-----------------------------------------------------------------------------------------
        //开始创建组件展现
        //-----------------------------------------------------------------------------------------
        var titleDiv = document.createElement( "DIV" );     //创建标题容器
        containerDiv.appendChild( titleDiv );               //添加到包裹容器

        var _innerText = (this.title=="")?"":this.title+"：";
        var _tmpText = this.mustMark+((_innerText.indexOf('*')!=-1)?_innerText.replace("*",''):_innerText);
        var _innerHTML  =(this.allowBlank!=undefined && this.allowBlank==false)?_tmpText:((_innerText.indexOf('*')!=-1)?_tmpText:_innerText);
        Sail.apply(titleDiv,{innerHTML:_innerHTML,align:"left",noWrap:true});  //定义对象
        
        //Sail.apply(titleDiv,{innerText:(this.title=="")?"":this.title+"：",align:"left",color:"#888888",noWrap:true});  //定义对象
        Sail.apply(titleDiv.style,{border:"0 #ababab solid",top:4,left:0,cursor:"default",position:"absolute",overflow:"hidden",marginLeft:3});
        this.titleWidth = titleDiv.offsetWidth;             //获得标题实际尺寸

        //-----------------------------------------------------------------------------------------
        //定义 数据层 （需要根据折行与否计算位置及尺寸）
        //-----------------------------------------------------------------------------------------
        var inputDivLeft   = this.titleWidth + 4;;
        var inputDivWidth  = this.width - this.titleWidth -4;
        var inputDivHeight = 22;
        this.boxWidth = inputDivWidth;        
        
        var inputDiv = document.createElement( "DIV" );         //创建值容器
        containerDiv.appendChild( inputDiv );                   //添加到包裹容器
        Sail.apply(inputDiv.style,{left:inputDivLeft,top:0,width:inputDivWidth,height:inputDivHeight,position:"absolute",overflow:"hidden"});


        var _config = {
            readOnly : true,
            blankText : "未选择...",
            width : inputDivWidth,
            openUrl : this.openUrl,
            openFn  : this.openFn,
            showValue : (this.text)?this.text:"text",
            dataValue : (this.value)?this.value:"id",
            renderTo: inputDiv    //渲染到
        };
        
        if(this.allowBlank!=undefined) _config.allowBlank  = this.allowBlank;
        
        this.el = new Ext.form.SelectField(_config);

        if(sc.isView()) {
            this.el.trigger.setDisplayed(false);
            inputDivWidth+=1;
        }
        
        this.text = (this.text)?this.text:"text";
        this.value = (this.value)?this.value:"id";
                
        if(this.disabled) this.el.disable();
        this.titleDiv = titleDiv;
        this.inputDiv = inputDiv;
  
        //this.el.setWidth(inputDivWidth+3);
        this.el.setWidth(inputDivWidth);
    }
    
});

/**************************************************************************************************
* 对象： Sail.widget.ext.selectFieldAdvanced
* 说明： Ext.form.SelectFieldAdvanced
*
**************************************************************************************************/
Sail.widget.ext.selectFieldAdvanced = function(config){
    
    Sail.apply(this, config);
    Sail.widget.ext.superclass.constructor.call(this);
    
}

Sail.extend(Sail.widget.ext.selectFieldAdvanced,Sail.widget.ext,{
    
    getValue : function(){
        //return this.el.getValue();
        var a = arguments;
        if(a.length==0) return this.el.getDataObj((this.value)?this.value:"id");
        
        if(a[0]==0)
            return this.el.getDataObj((this.value)?this.value:"id");
        else 
            return this.getText();
    },
    getText : function(){
        return this.el.getDataObj((this.text)?this.text:"text");
    },
    
    bindData : function(){
        //debugger;
        var a = arguments;
        var d = (a.length==1)?a[0]:a[1];
        this.setDataObj(d);
    },
    setDataObj : function(d){
        var _text  = (this.text)?this.text:"text";
        var _value = (this.value)?this.value:"id";
        
        
        var dataObj = {};
        try{
            dataObj[_value] = d[0];
            dataObj[_text] = d[1];
            
            this.el.setDataObj(dataObj);
            this.setValue(d[1]);
        }catch(e){
            Ext.Msg.alert('提示：', '在为selectField赋值时，发生异常！'+e.message); 
        }
    },
    
    setValue : function(v){
        this.el.setValue(v);
    },
    getData : function(){
        return this.el.getDataObj();
    },
    enable : function(){
        this.el.enable();
    },
    disable : function(){
        this.el.disable();
    },
    
    changeFunc : function(){
        var a = arguments;
        if(a.length==0){this.setNull();return;}
        
        this.el.enable();
        var newConfig = {};
        
        if(a.length==1){
            var config = a[0];
            if((typeof config ) =="object"){
                Ext.apply(newConfig,config);
            }else{
                newConfig.openFn=config;
            }
        }
        
        if(a.length==2){
            var data = a[1];
            var config = a[0];
            
            if((typeof config ) =="object"){
                if(config.openFn){
                    if(data instanceof Array){
                        for(var i=0,len=data.length;i<len;i++){
                            config.openFn = config.openFn.replace("{"+i+"}",data[i]);
                        }
                    }else{
                        config.openFn = config.openFn.replace("{0}",data);
                    }
                }
                Ext.apply(newConfig,config);
            }else{
                if(data instanceof Array){
                    for(var i=0,len=data.length;i<len;i++){
                        config = config.replace("{"+i+"}",data[i]);
                    }
                }else{
                    config = config.replace("{0}",data);
                }
                newConfig.openFn=config;
            }
        }
        
        if(this.el.openFn!="" && newConfig.openFn!=this.el.openFn)
            this.el.setValue("");

        Ext.apply(this.el,newConfig);
        
    },
    setNull : function(){
        this.el.setValue("");
        this.el.openFn  ="";
        this.el.openUrl ="";
        this.el.disable();
    },
    
    //=================================================================================================
    //方法： createWidgetElement
    //说明： 在设计窗口中创建组件本身
    //=================================================================================================
    createWidgetElement:function(){
        
        var containerDiv = this.getOCD();               //获得组件容器层
        
        //-----------------------------------------------------------------------------------------
        //开始创建组件展现
        //-----------------------------------------------------------------------------------------
        var titleDiv = document.createElement( "DIV" );     //创建标题容器
        containerDiv.appendChild( titleDiv );               //添加到包裹容器

        var _innerText = (this.title=="")?"":this.title+"：";
        var _tmpText = this.mustMark+((_innerText.indexOf('*')!=-1)?_innerText.replace("*",''):_innerText);
        var _innerHTML  =(this.allowBlank!=undefined && this.allowBlank==false)?_tmpText:((_innerText.indexOf('*')!=-1)?_tmpText:_innerText);
        Sail.apply(titleDiv,{innerHTML:_innerHTML,align:"left",noWrap:true});  //定义对象
        
        //Sail.apply(titleDiv,{innerText:(this.title=="")?"":this.title+"：",align:"left",color:"#888888",noWrap:true});  //定义对象
        Sail.apply(titleDiv.style,{border:"0 #ababab solid",top:4,left:0,cursor:"default",position:"absolute",overflow:"hidden",marginLeft:3});
        this.titleWidth = titleDiv.offsetWidth;             //获得标题实际尺寸

        //-----------------------------------------------------------------------------------------
        //定义 数据层 （需要根据折行与否计算位置及尺寸）
        //-----------------------------------------------------------------------------------------
        var inputDivLeft   = this.titleWidth + 4;;
        var inputDivWidth  = this.width - this.titleWidth -4;
        var inputDivHeight = 22;
        this.boxWidth = inputDivWidth;        
        
        var inputDiv = document.createElement( "DIV" );         //创建值容器
        containerDiv.appendChild( inputDiv );                   //添加到包裹容器
        Sail.apply(inputDiv.style,{left:inputDivLeft,top:0,width:inputDivWidth,height:inputDivHeight,position:"absolute",overflow:"hidden"});


        var _config = {
            readOnly : false,
            hideTrigger : false,
            blankText : "未选择...",
            width : inputDivWidth,
            openUrl : this.openUrl,
            openFn  : this.openFn,
            showValue : (this.text)?this.text:"text",
            dataValue : (this.value)?this.value:"id",
            renderTo: inputDiv    //渲染到
        };
        
        if(this.allowBlank!=undefined) _config.allowBlank  = this.allowBlank;
        
        this.el = new Ext.form.SelectFieldAdvanced(_config);
        
        this.text = (this.text)?this.text:"text";
        this.value = (this.value)?this.value:"id";
                
        if(this.disabled) this.el.disable();
        this.titleDiv = titleDiv;
        this.inputDiv = inputDiv;
  
        //this.el.setWidth(inputDivWidth+3);
        this.el.setWidth(inputDivWidth);
    }
    
});


/**************************************************************************************************
* 对象： Sail.widget.ext.sDate
* 说明： Ext.form.DateField
*
**************************************************************************************************/
Sail.widget.ext.sDate = function(config){
    Sail.apply(this, config);
    Sail.widget.ext.superclass.constructor.call(this);
}

Sail.extend(Sail.widget.ext.sDate,Sail.widget.ext,{
    enable : function(){
        this.titleDiv.style.color = "#000000";
        this.el.enable();
    },
    disable : function(){
        this.titleDiv.style.color = "#a0a0a0";
        this.el.disable();
    },
    getValue : function(){
        var getDate = this.el.getValue();
        
        return (getDate=="")?"":getDate.format("Ymd");
    },
    setValue : function(v){
        //debugger;
        var newDate = v.substr(0,4)+"-"+v.substr(4,2)+"-"+v.substr(6,2);
        
        this.el.setValue((v.length!=8)?"":newDate);
    },
    //=================================================================================================
    //方法： createWidgetElement
    //说明： 在设计窗口中创建组件本身
    //=================================================================================================
    createWidgetElement:function(){

        var containerDiv = this.getOCD();               //获得组件容器层
        
        //-----------------------------------------------------------------------------------------
        //开始创建组件展现
        //-----------------------------------------------------------------------------------------
        var titleDiv = document.createElement( "DIV" );     //创建标题容器
        containerDiv.appendChild( titleDiv );               //添加到包裹容器
        
        var _innerText = (this.title=="")?"":this.title+"：";
        var _tmpText = this.mustMark+((_innerText.indexOf('*')!=-1)?_innerText.replace("*",''):_innerText);
        var _innerHTML  =(this.allowBlank!=undefined && this.allowBlank==false)?_tmpText:((_innerText.indexOf('*')!=-1)?_tmpText:_innerText);
        
        _innerHTML = (_innerHTML==this.mustMark)?"":_innerHTML;
        Sail.apply(titleDiv,{innerHTML:_innerHTML,align:"left",noWrap:true});  //定义对象
        
        //Sail.apply(titleDiv,{innerText:(this.title=="")?"":this.title+"：",align:"left",color:"#888888",noWrap:true});  //定义对象
        Sail.apply(titleDiv.style,{border:"0 #ababab solid",top:4,left:0,cursor:"default",position:"absolute",overflow:"hidden",marginLeft:3});
        this.titleWidth = titleDiv.offsetWidth;             //获得标题实际尺寸

        //-----------------------------------------------------------------------------------------
        //定义 数据层 （需要根据折行与否计算位置及尺寸）
        //-----------------------------------------------------------------------------------------
        var inputDivLeft   = this.titleWidth + ((_innerText=="")?0:4);
        var inputDivWidth  = this.width - this.titleWidth -((_innerText=="")?0:4);
        var inputDivHeight = 22;
        this.boxWidth = inputDivWidth;        
        
        var inputDiv = document.createElement( "DIV" );         //创建值容器
        containerDiv.appendChild( inputDiv );                   //添加到包裹容器
        Sail.apply(inputDiv.style,{left:inputDivLeft,top:0,width:inputDivWidth,height:inputDivHeight,position:"absolute",overflow:"hidden"});
        
        var _config = {
            width : inputDivWidth,
            readOnly : true,
            format : "Y-m-d",
            renderTo: inputDiv    //渲染到
        };
        if(this.allowBlank!=undefined) _config.allowBlank  = this.allowBlank;

        this.el = new Ext.form.DateField(_config);
        
        if(sc.isView()) {
            this.el.trigger.setDisplayed(false);
            inputDivWidth+=0.1;
        }

        
        this.titleDiv = titleDiv;
        this.inputDiv = inputDiv;
        
        //this.el.setWidth(inputDivWidth+3);
        this.el.setWidth(inputDivWidth);
    }
    
});


/**************************************************************************************************
* 对象： Sail.widget.ext.combox
* 说明： 
*
**************************************************************************************************/
Sail.widget.ext.combox = function(config){
    Sail.apply(this, config);
    Sail.widget.ext.superclass.constructor.call(this);
    
    this.value="";
    this.text ="";
    //this.bindFlag = false;
}

Sail.extend(Sail.widget.ext.combox,Sail.widget.ext,{
    bindData:function(){
        var a = arguments;
        var d = (a.length==1)?a[0]:a[1];
        this.value=d;
        
        if(d instanceof Array){
            this.el.value=d[0];
            this.el.el.dom.value=d[1];
            this.el.lastSelectionText = d[1];
            this.el.el.removeClass("x-form-empty-field");
            this.el.el.removeClass(this.el.invalidClass);
            this.el.fireEvent('aftersetvalue', this.el, d[1],d[0]);
        }else{
            this.setValue(d);
        }
        
        //this.bindFlag = true;
        //if(this.bindFlag) this.setValue(d);
    },

    getValue : function(){
        return this.el.getValue();
    },
    getText : function(){
        return this.el.el.dom.value;
        /*
        return this.el.lastSelectionText;
        
        try{
            var index = this.el.view.getSelectedIndexes()[0];
            var r = this.el.store.getAt(index);
            var _textField =(this.fieldText)?this.fieldText:"text";
            return r.get(_textField);
        }catch(e){
            return "";
        }*/
    },
    setText : function(t){
    	this.el.el.dom.value=t;
    	this.el.lastSelectionText = t;
        this.el.el.removeClass("x-form-empty-field");    	
    },
    setValue : function(v){
        this.el.setValue(v);
    },
    enable : function(){
        this.titleDiv.style.color = "#000000";
        this.el.enable();
    },
    disable : function(){
        this.titleDiv.style.color = "#a0a0a0";
        this.el.disable();
    },
    load:function(){
        //this.clear();
        
        var _root,_textField,_valueField,_fields=[];
        var a =arguments;
        
        
        if(a.length==0){
            return;
        }else if(a.length==1){
            _url = a[0];

            _root       = this.root;
            _textField  = (this.fieldText)?this.fieldText:"text";
            _valueField = (this.fieldValue)?this.fieldValue:"code";
            _fields.push(_textField);
            _fields.push(_valueField);

            if(this.otherValues!=undefined){
               _fields =  _fields.concat(this.otherValues);
            }
            
            this.fieldText = _textField;
            this.fieldValue = _valueField;
        }else if(a.length==2){
            _url = a[0];

            var config  = a[1];
            _root       = (config.root)?config.root:this.root;
            _textField  = (config.fieldText)?config.fieldText:this.fieldText;
            _valueField = (config.fieldValue)?config.fieldValue:this.fieldValue;

            _fields.push(_textField);
            _fields.push(_valueField);

            if(config.otherValues!=undefined){
               _fields =  _fields.concat(config.otherValues);
               this.otherValues = [].concat(config.otherValues);
            }
            
            this.fieldText = _textField;
            this.fieldValue = _valueField;
        }
        
        //this.value="";
        this.setValue("");
        //this.el.value='';
        //this.el.el.dom.value='未选择...';
        
        this.el.store.removeAll();
        this.el.store.proxy= new Ext.data.HttpProxy({url: _url, method: 'POST'});
	    this.el.store.reader= new Ext.data.JsonReader({root: _root}, _fields);

        this.el.valueField   = this.fieldValue;        
        this.el.displayField = this.fieldText;      
        this.el.store.load();
        
    },
    removeAll : function(){
        alert("removeAll 方法已废弃！请使用clear方法替代！");
        this.value="";
        this.setValue("");
        this.el.store.removeAll();
    },
    clear: function(){
        this.value="";
        this.setValue("");
        this.el.store.removeAll();
    },
    
    //=================================================================================================
    //方法： createWidgetElement
    //说明： 在设计窗口中创建组件本身
    //=================================================================================================
    createWidgetElement:function(){

        var containerDiv = this.getOCD();               //获得组件容器层
        
        //-----------------------------------------------------------------------------------------
        //开始创建组件展现
        //-----------------------------------------------------------------------------------------
        var titleDiv = document.createElement( "DIV" );     //创建标题容器
        containerDiv.appendChild( titleDiv );               //添加到包裹容器
        
        var _innerText = (this.title=="")?"":this.title+"：";
        var _tmpText = this.mustMark+((_innerText.indexOf('*')!=-1)?_innerText.replace("*",''):_innerText);
        var _innerHTML  =(this.allowBlank!=undefined && this.allowBlank==false)?_tmpText:((_innerText.indexOf('*')!=-1)?_tmpText:_innerText);
        Sail.apply(titleDiv,{innerHTML:_innerHTML,align:"left",noWrap:true});  //定义对象

        Sail.apply(titleDiv.style,{color:"#000000",border:"0 #ababab solid",top:4,left:0,cursor:"default",position:"absolute",overflow:"hidden",marginLeft:3});
        this.titleWidth = titleDiv.offsetWidth;             //获得标题实际尺寸

        //-----------------------------------------------------------------------------------------
        //定义 数据层 （需要根据折行与否计算位置及尺寸）
        //-----------------------------------------------------------------------------------------
        var inputDivLeft   = this.titleWidth + 4;;
        var inputDivWidth  = this.width - this.titleWidth -4;
        var inputDivHeight = 22;
        this.boxWidth = inputDivWidth;
        
        var inputDiv = document.createElement( "DIV" );         //创建值容器
        containerDiv.appendChild( inputDiv );                   //添加到包裹容器
        Sail.apply(inputDiv.style,{left:inputDivLeft,top:0,width:inputDivWidth,height:inputDivHeight,position:"absolute",overflow:"hidden"});
        
        
        var _fields = [];
        var _textField =(this.fieldText)?this.fieldText:"text";
        var _valueField=(this.fieldValue)?this.fieldValue:"code";
        _fields.push(_textField);
        _fields.push(_valueField);
        
        if(this.otherValues!=undefined){
           _fields =  _fields.concat(this.otherValues);
        }

        this.fieldText = _textField;
        this.fieldValue = _valueField;

        var theObj = this;
        //debugger;
        var store = null;
        
        if(this.url && this.url!=""){
            store = new Ext.data.Store({
    	        proxy: new Ext.data.HttpProxy({url: this.url,method:"POST"}),
    	        reader: new Ext.data.JsonReader({root: this.root}, _fields)
            });

            var _mode = (this.mode)?this.mode:"local";
            if(_mode!='remote') {
                if(this.url.indexOf('?')!=-1||this.url.indexOf('txt')!=-1)
                    store.load();
            }
        }
        else
            store = new Ext.data.SimpleStore({fields:(this.fields)?this.fields:[],data : (this.dataArray)?this.dataArray:[]});
        
        var _config = {
            readOnly:false,
            minChars:2,
            store: store,
            displayField:_textField,
            name:_textField,
            valueField:_valueField,
            forceSelection : true,
            typeAhead: true,
            //mode: 'remote',
            triggerAction: 'all',
            emptyText:'未选择...',
            loadingText : '读取...',
            selectOnFocus:true,
            value:'',
            //lazyInit : false,
            renderTo: inputDiv    
        };    

        if(this.allowBlank!=undefined) _config.allowBlank  = this.allowBlank;
        if(sc.isView()) _config.readOnly = true;

        _config.mode = (this.mode)?this.mode:"local";
        
        if(this.listWidth!=undefined)
            _config.listWidth = this.listWidth;
            
        this.el = new Ext.form.ComboBox(_config);
        if(sc.isView()) {
            this.el.trigger.setDisplayed(false);
        }

        var _combox = this.el;
        var _w = this;
        
        /* 取消 by yjj 20080708 2

        store.on("datachanged",function(s){
            return;
            //debugger;
            var _record = Ext.data.Record.create([
                {name:theObj.fieldText,  type:"string"},
                {name:theObj.fieldValue, type:"string"}
            ]);
            var cd={};
            cd[theObj.fieldText]="未选择...";
            cd[theObj.fieldValue]="";
            var p = new _record(cd);
            
            if(s.data.items.length>0){
                if(s.data.items[0].get(theObj.fieldText)!='未选择...')
                    s.insert(0,p);
            }
            
            return;
            
            if(_w.value!=""){
                _combox.setValue(_w.value);
                _w.value="";
                _w.bindFlag = true;
            }else{
                _combox.setValue(_combox.getValue());
                _w.bindFlag = true;
            }
        })
        */

        //this.el.setWidth(inputDivWidth+3);     
        this.el.setWidth(inputDivWidth);     
        this.titleDiv = titleDiv;   
        this.inputDiv = inputDiv;
        
        this.el.addListener("beforeselect",function(c,r,index){
            //debugger;
            if(c.getValue()==r.get(theObj.fieldValue)){
                c.collapse();
                return false;
            }
        });
        
        
    }
    
});



/**************************************************************************************************
* 对象： Sail.widget.ext.button
* 说明： 
*
**************************************************************************************************/
Sail.widget.ext.button = function(config){
    
    Sail.apply(this, config);
    Sail.widget.ext.superclass.constructor.call(this);
    
}
Sail.extend(Sail.widget.ext.button,Sail.widget.ext,{
    
    enable : function(){
        this.el.enable();
    },
    disable : function(){
        this.el.disable();
    },
    getWidth : function(){
        return this.el.el.getBox().width;
    },
    createWidgetElement:function(){
        var config ={
            text:"　"+this.title,
            iconCls:'x-btn-left mybutton',
            cls: 'x-btn-text-icon',
            renderTo:this.getOCD()
        };
        
        config.tabindex = sc.getTabindex();
        
        if(sc.isView()) {
            if(this.title!='关闭' && this.title!='打印')
                if(this.alwaysShow!==true)
                    config.disabled = true;
        }
        this.el = new Ext.Button(config);

        if(sc.isView()) {
            if(this.title!='关闭' && this.title!='打印'){
                if(this.alwaysShow!==true)
                    this.el.hide();
            }
        }

    }
});






/**************************************************************************************************
* 对象： Sail.widget.ext.check
* 说明： 
*
**************************************************************************************************/
Sail.widget.ext.check = function(config){
    Sail.apply(this, config);
    Sail.widget.ext.superclass.constructor.call(this);
}
Sail.extend(Sail.widget.ext.check,Sail.widget.ext,{
    
    createWidgetElement:function(){
		this.el = new Ext.form.Checkbox({
			boxLabel : this.title,renderTo: this.getOCD()
		});
    }
});


Sail.widget.ext.checkGroup = function(config){
    this.uncheckValue = "-1";
    this.checkValue   = "1";

    Sail.apply(this, config);
    Sail.widget.ext.superclass.constructor.call(this);
    
    this.el = null;
    this.checkerList = [];
    this.value = "";
}
Sail.extend(Sail.widget.ext.checkGroup,Sail.widget.ext,{
    bindData : function(){
        //debugger;
        var a = arguments;
        var d = (a.length==1)?a[0]:a[1];
        this.setValue(d);
    },
    
    getValue : function(){
        var values = [];
        for(var i=0;i<this.checkerList.length;i++){
            values.push((this.checkerList[i].checked)?this.checkValue:this.uncheckValue);
        }
        return (values.length>0)?values.join(','):"";
    },
    getSelected : function(){
        var selected = [];
        for(var i=0;i<this.checkerList.length;i++){
            if(this.checkerList[i].checked)
                selected.push(this.checkerList[i].value);
        }
        return selected;
    },
    select : function(value){
        var values = (value instanceof Array)?value:[value];
        
        for(var i=0;i<values.length;i++){
            if(this.checkerList[i].value==values[i])
                this.checkerList[i].checked = true;
        }
    },
    setValue : function(v){
        var values = v.split(',');
        for(var i=0;i<this.checkerList.length;i++){
            this.checkerList[i].checked = (values[i]!=undefined)?((values[i]==this.uncheckValue)?false:true):false;
        }
    },
    
    recreate2 : function(config){
        if(config.labels == undefined)  return;

        this.checkType  = (config.checkType!=undefined)?config.checkType:"check";
        this.labels     = config.labels;
        this.value      ='';        
        this.checkerList= [];
        
        this.inputDiv.innerHTML = "";
        
        for(var i=0;i<this.labels.length;i++){
            var checker = document.createElement( "INPUT" );
            checker.type=(this.checkType=='check')?'checkbox':'radio';
            checker.name = this.groupName;
            
            this.inputDiv.appendChild( checker );
            this.checkerList.push(checker);
            
            var label = document.createElement( "LABEL" );     
            label.innerHTML=this.labels[i]+"";
            this.inputDiv.appendChild( label );
        }
    },
    
    recreate : function(config){
        this.clear();
        //debugger;
        for(var i=0;i<config.labels.length;i++){
            var _type = (this.checkType=='check')?'checkbox':'radio';
            var _name = this.groupName;
            var _id   = (config.labelsValue==undefined)?"check__"+i:config.labelsValue[i];
            
            var _html="<INPUT TYPE='"+_type+"' value='"+_id+"' NAME='"+_name+"' >";
            var checker = document.createElement(_html);
            this.inputDiv.appendChild( checker );
            
            this.checkerList.push(checker);
            
            var label = document.createElement( "LABEL" );     
            label.innerHTML=config.labels[i]+"";
            this.inputDiv.appendChild( label );
            
            if(this.clickEvent!=undefined){
                Ext.get(checker).addListener('click',this.clickEvent);
            }
        }
        
        if(this.afterCreate!=undefined && typeof this.afterCreate=='function'){
            this.afterCreate.call('',this.checkerList);
        }
    },
    
    clear : function(){
        this.value      ='';        
        this.checkerList= [];
        this.inputDiv.innerHTML = "";
    },
    
    enable : function(){
        this.titleDiv.style.color = "#000000";
        for(var i=0;i<this.checkerList.length;i++){
            this.checkerList[i].disabled=false;
        }
        //this.el.enable();
    },
    disable : function(){
        this.titleDiv.style.color = "#a0a0a0";
        for(var i=0;i<this.checkerList.length;i++){
            this.checkerList[i].disabled=true;
        }
        //this.el.disable();
    },

    load : function(config){

        if(config.url         == undefined)  config.url         = this.url;
        if(config.root        == undefined)  config.root        = this.root;
        if(config.fieldText   == undefined)  config.fieldText   = this.fieldText;
        if(config.fieldValue  == undefined)  config.fieldValue  = this.fieldValue;
        if(config.labels      == undefined)  config.labels      = this.labels;
        if(config.labelsValue == undefined)  config.labelsValue = this.labelsValue;
        
        if(config.url==undefined) {
            Ext.Msg.alert('提示','没有找到数据源的URL！');
            return;
        }
        
        var theObj = this;
        var _callback = function(flag,getData){
            
            //---------------------------------------------------------
            //---------------------------------------------------------
            var itemList = sc.getDataObj2(getData,config.root); 
            if(itemList==null || itemList==undefined){
                //Ext.Msg.alert('提示','没有找到root指定的数据集合！');
                return;
            }
            
            //---------------------------------------------------------
            //2008-12-04 修改当itemList为单个对象时的疏漏
            //---------------------------------------------------------
            itemList = (itemList.length)?itemList:[itemList];
            
            if(theObj.spliceFunc!=undefined && typeof(theObj.spliceFunc)=='function'){
                for(var i=itemList.length-1;i>=0;i--){
                    if(theObj.spliceFunc(itemList[i]))
                        itemList.splice(i,1);
                }
            }
            
            //---------------------------------------------------------
            //---------------------------------------------------------
            var createConfig = {labels:[],labelsValue:[]};
            if(config.labels!=undefined){
                for(var i=0;i<config.labels.length;i++){
                    createConfig.labels.push(config.labels[i]);
                    createConfig.labelsValue.push(config.labelsValue[i]);
                }
            }
            
            //---------------------------------------------------------
            //---------------------------------------------------------
            for(var i=0;i<itemList.length;i++){
                createConfig.labels.push(itemList[i][config.fieldText]);
                createConfig.labelsValue.push(itemList[i][config.fieldValue]);
            }
            
            //---------------------------------------------------------
            //---------------------------------------------------------
            theObj.recreate(createConfig);
        };

        sc.postData(config.url,{},_callback);
            
    },
    
    createWidgetElement:function(){

        var containerDiv = this.getOCD();                   //获得组件容器层
        //---------------------------------------------------------------------------------------------
        var titleDiv = document.createElement( "DIV" );     //创建标题容器
        containerDiv.appendChild( titleDiv );               //添加到包裹容器

        var _innerText = (this.title=="")?"":this.title+"：";
        var _tmpText = this.mustMark+((_innerText.indexOf('*')!=-1)?_innerText.replace("*",''):_innerText);
        var _innerHTML  =(this.allowBlank!=undefined && this.allowBlank==false)?_tmpText:((_innerText.indexOf('*')!=-1)?_tmpText:_innerText);
        Sail.apply(titleDiv,{innerHTML:_innerHTML,align:"left",noWrap:true});  //定义对象
        
        Sail.apply(titleDiv.style,{color:"#000000",border:"0 #ababab solid",top:4,left:0,cursor:"default",position:"absolute",overflow:"hidden",marginLeft:3});
        this.titleWidth = titleDiv.offsetWidth;             //获得标题实际尺寸
        
        //-----------------------------------------------------------------------------------------
        //定义 数据层 （需要根据折行与否计算位置及尺寸）
        //-----------------------------------------------------------------------------------------
        var inputDivLeft   = this.titleWidth + 4;;
        var inputDivWidth  = this.width - this.titleWidth -7;
        var inputDivHeight = this.height;
        this.boxWidth = inputDivWidth;
        
        var inputDiv = document.createElement( "DIV" );     //创建值容器
        containerDiv.appendChild( inputDiv );               //添加到包裹容器
        Sail.apply(inputDiv.style,{border:'1px #B5B8C8 solid',left:inputDivLeft,top:0,width:inputDivWidth,height:this.height,position:"absolute",overflow:"hidden"});
        
        //---------------------------------------------------------------------------------------------
        var _config ={width:inputDivWidth,renderTo:inputDiv};
        if(this.allowBlank!=undefined) _config.allowBlank  = this.allowBlank;

        this.groupName = inputDiv.uniqueID+"_group";
        this.checkType = (this.checkType==undefined)?"check":this.checkType;

        this.root       = (this.root==undefined)?"dataset.simplecombobox":this.root;
        this.fieldText  = (this.fieldText==undefined)?"text":this.fieldText;
        this.fieldValue = (this.fieldValue==undefined)?"value":this.fieldValue;

        if(this.labels !=undefined){
            for(var i=0;i<this.labels.length;i++){

                var _type = (this.checkType=='check')?'checkbox':'radio';
                var _name = this.groupName;
                var _id   = (this.labelsValue==undefined)?"check__"+i:this.labelsValue[i];
                
                var _html="<INPUT TYPE='"+_type+"' value='"+_id+"' NAME='"+_name+"' >";
                var checker = document.createElement(_html);
                inputDiv.appendChild( checker );
                
                this.checkerList.push(checker);
                
                var label = document.createElement( "LABEL" );     
                label.innerHTML=this.labels[i]+"";
                inputDiv.appendChild( label );
                
                if(this.clickEvent!=undefined){
                    Ext.get(checker).addListener('click',this.clickEvent);
                }
            }
        }

        //---------------------------------------------------------------------------------------------
        this.titleDiv = titleDiv;
        this.inputDiv = inputDiv;

        //---------------------------------------------------------------------------------------------
        var theObj = this;
        if(this.url!=undefined){
            var _callback = function(flag,getData){
                
                var itemList = sc.getObjFromPostData(getData,theObj.root);
                if(itemList==null || itemList==undefined)
                    return;

                if(theObj.spliceFunc!=undefined && typeof(theObj.spliceFunc)=='function'){
                    for(var i=itemList.length-1;i>=0;i--){
                        if(theObj.spliceFunc(itemList[i]))
                            itemList.splice(i,1);
                    }
                }
                
                for(var i=0;i<itemList.length;i++){
    
                    var _type = (theObj.checkType=='check')?'checkbox':'radio';
                    var _name = theObj.groupName;
                    var _id   = itemList[i][theObj.fieldValue];
                    var _html="<INPUT TYPE='"+_type+"' value='"+_id+"' NAME='"+_name+"' >";
                    var checker = document.createElement(_html);
                    
                    theObj.inputDiv.appendChild( checker );
                    theObj.checkerList.push(checker);
                    
                    var label = document.createElement( "LABEL" );     
                    label.innerHTML = itemList[i][theObj.fieldText];
                    theObj.inputDiv.appendChild( label );
                    
                    if(theObj.clickEvent!=undefined){
                        Ext.get(checker).addListener('click',theObj.clickEvent);
                    }
                    
                }
            };
            sc.postData(this.url,{},_callback);
        }

    }
});


/**************************************************************************************************
* 对象： Sail.widget.ext.radio
* 说明： 
*
**************************************************************************************************/
Sail.widget.ext.radio = function(config){
    Sail.apply(this, config);
    Sail.widget.ext.superclass.constructor.call(this);
}
Sail.extend(Sail.widget.ext.radio,Sail.widget.ext,{
    
    createWidgetElement:function(){
		this.el = new Ext.form.Radio({
		    boxLabel : this.title,name : this.groupID,renderTo: this.getOCD()
		});
    }
});


/**************************************************************************************************
* 对象： Sail.widget.ext.textArea
* 说明： 
*
**************************************************************************************************/
Sail.widget.ext.textArea = function(config){
    this.align = 'horizontal';    //vertical
    Sail.apply(this, config);
    Sail.widget.ext.superclass.constructor.call(this);
}

Sail.extend(Sail.widget.ext.textArea,Sail.widget.ext,{
    
    getValue : function(){
        return this.el.getValue();
    },
    setValue : function(v){
        this.el.setValue(v);
    },
    
    enable : function(){
        this.titleDiv.style.color = "#000000";
        this.el.enable();
    },
    disable : function(){
        this.titleDiv.style.color = "#a0a0a0";
        this.el.disable();
    },

    createWidgetElement:function(){

        var containerDiv = this.getOCD();                   //获得组件容器层
        //---------------------------------------------------------------------------------------------
        var titleDiv = document.createElement( "DIV" );     //创建标题容器
        containerDiv.appendChild( titleDiv );               //添加到包裹容器

        //Sail.apply(titleDiv,{innerText:(this.title=="")?"":this.title+"：",align:"left",noWrap:true});  //定义对象
        //Sail.apply(titleDiv.style,{color:"#000000",border:"0 #ababab solid",top:4,left:0,cursor:"default",position:"absolute",overflow:"hidden",marginLeft:3});
        //this.titleWidth = titleDiv.offsetWidth;             //获得标题实际尺寸


        var _innerText = (this.title=="")?"":this.title+"：";
        if(this.align=='vertical') _innerText=_innerText.replace("：",'');
        
        var _tmpText = this.mustMark+((_innerText.indexOf('*')!=-1)?_innerText.replace("*",''):_innerText);
        var _innerHTML  =(this.allowBlank!=undefined && this.allowBlank==false)?_tmpText:((_innerText.indexOf('*')!=-1)?_tmpText:_innerText);
        Sail.apply(titleDiv,{innerHTML:_innerHTML,align:"left",noWrap:true});  //定义对象
        
        var cssConfig = {color:"#000000",border:"0 #ababab solid",top:4,left:0,cursor:"default",position:"absolute",overflow:"hidden",marginLeft:3};
        if(this.align=='vertical'){
            cssConfig.layoutFlow = 'vertical-ideographic';
            cssConfig.paddingTop = 4;
            cssConfig.paddingRight = 2;
        }
        
        Sail.apply(titleDiv.style,cssConfig);
        this.titleWidth = titleDiv.offsetWidth;             //获得标题实际尺寸
        this.titleHeight = titleDiv.offsetHeight;
        
        containerDiv.style.height = titleDiv.offsetHeight;
        
        this.height =(this.height>titleDiv.offsetHeight)?this.height:titleDiv.offsetHeight;
        
        //-----------------------------------------------------------------------------------------
        //定义 数据层 （需要根据折行与否计算位置及尺寸）
        //-----------------------------------------------------------------------------------------
        var inputDivLeft   = this.titleWidth + 4;;
        var inputDivWidth  = this.width - this.titleWidth -8;
        var inputDivHeight = this.height;
        
        var inputDiv = document.createElement( "DIV" );     //创建值容器
        containerDiv.appendChild( inputDiv );               //添加到包裹容器
        Sail.apply(inputDiv.style,{left:inputDivLeft,top:0,width:inputDivWidth,height:inputDivHeight,position:"absolute",overflow:"hidden"});
        
        
        var config = {
			boxLabel : this.title,
			width:inputDivWidth,
			height:this.height,
			renderTo: inputDiv
        };
        if(this.readOnly!=undefined) config.readOnly = this.readOnly;
		this.el = new Ext.form.TextArea(config);
        this.titleDiv = titleDiv;
    }
});


/**************************************************************************************************
* 对象： Sail.widget.ext.label
* 说明： 
*
**************************************************************************************************/
Sail.widget.ext.label = function(config){
    Sail.apply(this, config);
    Sail.widget.ext.superclass.constructor.call(this);
}

Sail.extend(Sail.widget.ext.label,Sail.widget.ext,{
    
    setLabel : function(config){
        if(config.title!=undefined){
            this.setTitle(config.title);
        }
    },
    updateLabel:function(_html){
        if(this.el)
            this.el.innerHTML = _html;
    },
    setTitle : function(_title){
        
        var ci = (this.useIcon)?3:1;
        this.el.children[0].rows[0].cells[ci].innerText = _title;
        this.title = _title;
        
        var color = (this.color)?this.color:"#FA6003";        
        if(this.useIcon)
            this.el.innerHTML = "<table height=21 cellspacing=0><tr height=21><td class='label_null' width=4></td>"
            +"<td class='label_normal' width=16></td><td class='label_null'width=4></td>"
            +"<td height=21 nowrap style='color:"+color+";font:bold 12px tahoma,arial,verdana,sans-serif;padding-top:2'>"+this.title+"</td>";
        else
            this.el.innerHTML =  "<table height=21 cellspacing=0><tr height=21><td class='label_null' width=4></td>"
                +"<td height=21 nowrap style='color:"+color+";font:bold 12px tahoma,arial,verdana,sans-serif;padding-top:2'>"+this.title+"</td>";

        var nWidth = this.el.children[0].offsetWidth;
        this.OCD.style.width = nWidth;
        this.el.style.width = nWidth+100;

    },
    
    createWidgetElement:function(){
        var containerDiv = this.getOCD();
        var labelDiv = document.createElement( "DIV" );     //创建标题容器
        containerDiv.appendChild( labelDiv );               //添加到包裹容器
        Sail.apply(labelDiv.style,{border:"0 #ababab solid",left:0,top:0,height:21,cursor:"default",position:"absolute"});
        
        if(this.bgColor !=undefined) containerDiv.style.backgroundColor = this.bgColor;
        var color = (this.color)?this.color:"#FA6003";
        var fontStyle = (this.font)?this.font:"bold 12px tahoma,arial,verdana,sans-serif";        
        
        if(this.useIcon)
            labelDiv.innerHTML = "<table height=21 cellspacing=0><tr height=21><td class='label_null' width=4></td>"
            +"<td class='label_normal' width=16></td><td class='label_null'width=4></td>"
            +"<td height=21 nowrap style='color:"+color+";font:"+fontStyle+";padding-top:2'>"+this.title+"</td>";
        else
            labelDiv.innerHTML =  "<table height=21 cellspacing=0><tr height=21><td class='label_null' width=4></td>"
                +"<td height=21 nowrap style='color:"+color+";font:"+fontStyle+";padding-top:2'>"+this.title+"</td>";
        
        this.el = labelDiv;
    }
});


/**************************************************************************************************
* 对象： Sail.widget.ext.form
* 说明： 
*
**************************************************************************************************/
Sail.widget.ext.form = function(config){
    Sail.apply(this, config);
    Sail.widget.ext.superclass.constructor.call(this);
}

Sail.extend(Sail.widget.ext.form,Sail.widget.ext,{
    
    //=================================================================================================
    //方法： createWidgetElement
    //说明： 在设计窗口中创建组件本身
    //=================================================================================================
    createWidgetElement:function(){

        var containerDiv = this.getOCD();               //获得组件容器层
        //---------------------------------------------------------------------------------------------
        
        //---------------------------------------------------------------------------------------------
        this.el  = sampleGrid;
    }
    
});


/**************************************************************************************************
* 对象： Sail.widget.ext.myForm
* 说明： 
*
**************************************************************************************************/
Sail.widget.ext.myForm = function(config){
    this.OCBC = null;
    this.barDiv = null;
    
    Sail.apply(this, config);
    Sail.widget.ext.superclass.constructor.call(this);
}

Sail.extend(Sail.widget.ext.myForm,Sail.widget.ext,{
    
    addItems : function(config){
        var _additems  = config.additems;
        var _arranges  = config.arranges;
        var _afterItem = config.afterItem;
        var _afterLine = config.afterLine;
        
        //-----------------------------------------------------------
        if(this.formIndex==undefined){
            for(var i=0;i<sc.dataContainer.length;i++){
                if(sc.dataContainer[i].id==this.id){
                    this.formIndex = i;
                    break;
                }
            }
        }

        //-----------------------------------------------------------
        var tmpForm = {subWidgets:[]};          //临时空白表单
        sc.addWidgt2Form(_additems,tmpForm);    //转换成页面组件定义对象
        
        var formItems = sc.dataContainer[this.formIndex].subWidgets;                 //取得已有表单项目
        sc.dataContainer[this.formIndex].subWidgets = formItems.insertItems(_afterItem,tmpForm.subWidgets);//插入结算协议表单项
        sc.dataArrange[this.formIndex] = sc.dataArrange[this.formIndex].insertItems(_afterLine,_arranges);
        
        var oldHeight = sc.dataContainer[this.formIndex].height;
        sc.arrangeFormItem_core(sc.dataContainer[this.formIndex],sc.dataArrange[this.formIndex]);
        var newHeight = sc.dataContainer[this.formIndex].height;
        
        //-----------------------------------------------------------
        //-----------------------------------------------------------
        var sonWidgetsDefine = [];
        Ext.apply(sonWidgetsDefine,sc.dataContainer[this.formIndex].subWidgets);

        for(var i=0,len=sonWidgetsDefine.length;i<len;i++){
            var widget = $2(sonWidgetsDefine[i].id);
            if(widget!=undefined){
                widget.move2(sonWidgetsDefine[i].left,sonWidgetsDefine[i].top);
            }else{
                sonWidgetsDefine[i].add2Win   = this.OCBC;
                sonWidgetsDefine[i].add2Group = sc.el;
            
                var newWidget = eval("new Sail.widget."+sonWidgetsDefine[i].type+"();");
                newWidget.create(sonWidgetsDefine[i]);
            }
        }
        this.setHeight(newHeight);

        return newHeight-oldHeight;
    },
    
    removeItems : function(config){
        //-----------------------------------------------------------
        if(this.formIndex==undefined){
            for(var i=0;i<sc.dataContainer.length;i++){
                if(sc.dataContainer[i].id==this.id){
                    this.formIndex = i;
                    break;
                }
            }
        }
        
        //-----------------------------------------------------------
        var _itemList = config.itemList;
        
        for(var i=0;i<_itemList.length;i++){
            var w = $(_itemList[i]);
            
            var formItems = sc.dataContainer[this.formIndex].subWidgets;
            for(var k=formItems.length-1;k>=0;k--){
                if(formItems[k].id==w.id){
                    formItems.splice(k,1);
                    break;
                }
            }

            var arranges= sc.dataArrange[this.formIndex];
            for(var j=0;j<arranges.length;j++){
                for(var k=0;k<arranges[j].sub.length;k++){
                    if(arranges[j].sub[k]==_itemList[i]){
                        arranges[j].sub.splice(k,1);
                    }
                }
            }
            w.destroy();
        }
        
        //-----------------------------------------------------------
        //-----------------------------------------------------------
        var arranges= sc.dataArrange[this.formIndex];
        for(var i=arranges.length-1;i>=0;i--){
            if(arranges[i].sub.length==0){
                arranges.splice(i,1);
            }
        }
        var oldHeight = sc.dataContainer[this.formIndex].height;
        sc.arrangeFormItem_core(sc.dataContainer[this.formIndex],sc.dataArrange[this.formIndex]);
        var newHeight = sc.dataContainer[this.formIndex].height;
        
        //-----------------------------------------------------------
        //-----------------------------------------------------------
        for(var i=0;i<sc.dataContainer[this.formIndex].subWidgets.length;i++){
            var widget = $(sc.dataContainer[this.formIndex].subWidgets[i].id);
            widget.move2(sc.dataContainer[this.formIndex].subWidgets[i].left,sc.dataContainer[this.formIndex].subWidgets[i].top);
        }
        //-----------------------------------------------------------
        //-----------------------------------------------------------
        this.setHeight(newHeight);
        return newHeight-oldHeight;
    },
    
    createWidgetElement:function(){
        var containerDiv = this.getOCD();
        
        var tbarDiv = document.createElement( "DIV" );     //创建标题容器
        containerDiv.appendChild( tbarDiv );               //添加到包裹容器
        Sail.apply(tbarDiv.style,{border:"0 #ababab solid",left:0,top:0,height:21,cursor:"default",position:"absolute"});
        var tbarID = this.id+"_tbar";
        
        tbarDiv.innerHTML = "<table id='"+tbarID+"' style='cursor:hand' height=21 cellspacing=0>"
            +"<tr height=21><td class='tbar_lcorner' width=2></td><td width=4 class='tbar_back'></td>"
            +"<td class='tbar_app'  width=16></td><td width=4 class='tbar_back'></td>"
            +"<td height=21 class='tbar_back' style='padding-top:3'>"+this.title+"</td>"
            +"<td width=2 class='tbar_back'></td><td class='tbar_right' width=22></td></tr></table>";
        
        this.barDiv = tbarDiv;
        
        var tFormDiv = document.createElement( "DIV" );     //创建标题容器
        tFormDiv.id='yujunjie';
        
        containerDiv.appendChild( tFormDiv );               //添加到包裹容器
        Sail.apply(tFormDiv.style,{border:"0 #ababab solid",left:0,top:21,height:this.height-21,cursor:"default",position:"absolute"});

        this.el = new Ext.FormPanel({
            animCollapse:false,
            labelAlign: 'top',
            bodyStyle:'padding:5px',
            width: this.width,
            height:this.height-21,
            autoWidth: this.autoWidth,
            renderTo:tFormDiv,
            items: [{
                layout:'column',
                border:false
            }]
            
        });

        this.OCBC   = this.el.body.dom;
        var theObj = this;
        
        Ext.get(tbarID).on("click",function(e,o){
            
            var moveHeight = 0;
            
            if(!theObj.el.collapsed){
                theObj.el.collapse();
                theObj.barDiv.style.borderBottom = '1px solid #99BBE8';
                moveHeight = theObj.height-21;
            }
            else {
                theObj.el.expand();
                theObj.barDiv.style.borderBottom = '0px solid #99BBE8';
                moveHeight = -theObj.height+21;
            }
            
            for(var i=0;i<sc.widgets.length;i++){
                if(sc.widgets[i].id!=theObj.id){
                    var o = sc.getWidgetByID(sc.widgets[i].id);
                    if(o.top>theObj.top){
                        o.setTop(o.top-moveHeight);
                        //alert();
                        //o.el.getView().updateHeaders();
                    }
                }
            }
        })
    }
});

/**************************************************************************************************
* 对象： Sail.widget.ext.dayPanel
* 说明： 
*
**************************************************************************************************/
Sail.widget.ext.dayPanel = function(config){
    this.OCBC = null;
    this.barDiv = null;
    this.autoChange = true;
    
    Sail.apply(this, config);
    Sail.widget.ext.superclass.constructor.call(this);
    
    this.dayBlocks = [];
    this.selectedDate = "";
}

Sail.extend(Sail.widget.ext.dayPanel,Sail.widget.ext,{
    
    //-----------------------------------------------------------
    getFirstWeek:function(year,month){
      return (new Date(year,month-1,1)).getDay()
    },
    getThisDays:function(year,month){
      return (new Date(year,month,0)).getDate()
    },
    getLastDays:function(year,month){
      return (new Date(year,month-1,0)).getDate()
    },
    fullNumber:function(num){
      return (parseInt(num,10)<10)?"0"+num:""+num;
    },
    getDateList:function(year,month,day,mode){
    
      var _year =(year==null)?2008:parseInt(year,10);
      var _month=(month==null)?1:parseInt(month,10);
      var _day  =(day==null)?1:parseInt(day,10);
      var _mode =(mode==null)?0:parseInt(mode,10);
      
      var _lastMonth = _month-1;
      var _lastYear  = _year-1;
      var _nextMonth = _month+1;
      var _nextyear  = _year+1;
      
      var fw=this.getFirstWeek(_year,_month);
      var ld=this.getLastDays(_year,_month);
      var td=this.getThisDays(_year,_month);
    
      var isnd=false;
      var d=1;

      var aWeek=[];
      var aWeekFlag=[];
      var allDay = [];
      var allDayFlag = [];
      var tf = (fw==0)?fw+7:fw;     //如第一天是星期天.+7.保证可以看到上个月的日期
    
      //----------------------------------------------------------------
      //第一行上月日期+第一行本月日期
      //----------------------------------------------------------------
      for (l=(ld-tf+1);l<=ld;l++)  {
        var tmpDate = (_lastMonth==0)?""+_lastYear+"-12-"+this.fullNumber(l):_year+"-"+this.fullNumber(_lastMonth)+"-"+this.fullNumber(l);
        tmpDate = (_mode==0)?this.fullNumber(l):tmpDate;
        aWeek.push(tmpDate);
        aWeekFlag.push(0);
      }
      
      for (f=tf;f<=6;f++) {
        var tmpDate = (_mode==0)?this.fullNumber(d):_year+"-"+this.fullNumber(_month)+"-"+this.fullNumber(d);
        aWeek.push(tmpDate);
        aWeekFlag.push(1);
        d++;
      }
      allDay.push(aWeek);
      allDayFlag.push(aWeekFlag);
    
      //----------------------------------------------------------------
      //其他行本月日期
      //----------------------------------------------------------------
      for (i=2;i<7;i++){
        aWeek = [];
        aWeekFlag = [];
        
        for (j=1;j<8;j++){
          if (isnd){                            //下个月的日期
            var tmpDate = (_nextMonth==13)?""+_nextyear+"-01-"+this.fullNumber(d):_year+"-"+this.fullNumber(_nextMonth)+"-"+this.fullNumber(d);
            tmpDate = (_mode==0)?this.fullNumber(d):tmpDate;
            aWeek.push(tmpDate);
            aWeekFlag.push(0);
          }else{                                //本月的日期
            var tmpDate = (_mode==0)?this.fullNumber(d):_year+"-"+this.fullNumber(_month)+"-"+this.fullNumber(d);
            aWeek.push(tmpDate);
            aWeekFlag.push(1);
          }
          
          if (d==td){       //判断是否为本月的日期
            isnd=true;
            d=0;
          }
          d++;
        }
        allDay.push(aWeek);
        allDayFlag.push(aWeekFlag);
      }
      return {dateList:allDay,flagList:allDayFlag};
    },

    //-----------------------------------------------------------    
    getPlaceByDay:function(day){
        for(var i=0;i<this.dateList.length;i++){
            for(var j=0;j<7;j++){
                if(this.flagList[i][j]==1){
                    var allDay = this.year+"-"+this.fullNumber(this.month)+"-"+this.dateList[i][j];
                    if(allDay==day){
                        return {row:i,col:j};
                    }
                }
            }
        }
        return null;
    },
    //-----------------------------------------------------------    
    createDatePanel : function(){
        var _blockWidth = 30;
        var _spacing    = (this.blockSpace==undefined)?6:this.blockSpace;
        
        var _left = 10;
        var _top  = 70;
        
        this.dayBlocks = [];
        for(var i=0;i<6;i++){
            this.dayBlocks.push([]);
            for(var j=0;j<7;j++){
                var dayDiv   = document.createElement( "DIV" );    
                var _color   = (j==0||i==6)?"#FA6003":"#666666";
                var _bord    = "1px #DEDEDE solid";
                var _cursor  = "hand";
                var _bgColor = "#ffffff";//:(this.flagList[i]==1)?"#D1E5FC":"#ffffff";
                
                Sail.apply(dayDiv.style,{
                    left    : _left,
                    top     : _top,
                    width   : _blockWidth,
                    height  : _blockWidth,
                    position: "absolute",
                    textAlign  : 'center',
                    fontSize   :'10px',
                    paddingTop : 2,
                    cursor : _cursor,
                    border : _bord,
                    color  : _color,
                    backgroundColor : _bgColor
                });
                dayDiv.id = "dayblock_"+i+"_"+j;
                this.OCBC.appendChild(dayDiv);      //添加到设计窗口

                this.dayBlocks[i].push(dayDiv);
                var theObj = this;
                var _block = Ext.get(dayDiv.id);
                _block.on('click',this.onDateClick,this);
                _block.on('mouseover',function(e,field){
                    var _row = parseInt(field.id.split('_')[1],10);
                    var _col = parseInt(field.id.split('_')[2],10);
                    var flag = theObj.isCurrentMonth(_row,_col);
                    if(flag){ 
                        if(field.style.borderColor!='#dedede')
                            field.style.borderColor = "#FA6003";
                    }
                });
                _block.on('mouseout',function(e,field){
                    var _row = parseInt(field.id.split('_')[1],10);
                    var _col = parseInt(field.id.split('_')[2],10);
                    var flag = theObj.isCurrentMonth(_row,_col);
                    if(flag)
                        if(field.style.borderColor=='#dedede')
                            field.style.borderColor = "#DEDEDE";
                        else
                            field.style.borderColor = "#999999";
                    else
                        field.style.borderColor = "#ffffff";
                });
                
                _left+=_blockWidth+_spacing;
            }
            _left=10;
            _top+=_blockWidth+_spacing;
        }
    },
    changeBlock : function(row,col,config){
        var tmp = this.dayBlocks[row][col];

        if(config.date!=undefined){
            //tmp.innerText = config.date;
            tmp.innerText = (config.isThisMonth===1)?config.date:"";
            tmp.style.borderColor = (config.isThisMonth===1)?"#999999":"#ffffff";
        }
        
        if(config.isThisMonth!=undefined){
            var _color = (col==0||col==6)?"#FA6003":"#333333";
            _color = (config.isThisMonth===1)?_color:"#c0c0c0";
            var _cursor = (config.isThisMonth===1)?"hand":"default";
            
            tmp.style.color = _color;
            tmp.style.cursor= _cursor;
        }
                
        if(config.haveData!=undefined){
            tmp.style.backgroundColor = (config.haveData===true)?"#D1E5FC":"#ffffff";
        }
        
        if(config.noPlan===true){
            tmp.style.backgroundColor = "#ffffff";
            tmp.style.borderColor = "#DEDEDE";
        }

        if(config.resetBgColor!=undefined){
            tmp.style.backgroundColor = "#ffffff";
        }
    },
    
    setNoPlan : function(row,col){
        var config = {noPlan:true};
        var a = arguments;
        if(a.length==1){
            var place = this.getPlaceByDay(a[0]);
            if(place!=null){
                this.changeBlock(place.row,place.col,config);
            }
        }
        else
            this.changeBlock(a[0],a[1],config);
    },
    
    setNoPlans : function(havePlans){
        if(havePlans.length==0){
            for(var i=0;i<this.dateList.length;i++){
                for(var j=0;j<7;j++){
                    if(this.flagList[i][j]==1){
                        this.setNoPlan(i,j);
                    }
                }
            }
            return;
        }
        
        var strHavePlans = havePlans.join(",");
        
        for(var i=0;i<this.dateList.length;i++){
            for(var j=0;j<7;j++){
                if(this.flagList[i][j]==1){
                    var allDay = this.year+"-"+this.fullNumber(this.month)+"-"+this.dateList[i][j];
                    if(strHavePlans.indexOf(allDay)==-1)
                        this.setNoPlan(i,j);
                }
            }
        }
    },
    
    setHaveData : function(row,col){
        var config = {haveData:true};
        var a = arguments;
        if(a.length==1){
            var place = this.getPlaceByDay(a[0]);
            if(place!=null){
                this.changeBlock(place.row,place.col,config);
            }
        }
        else
            this.changeBlock(a[0],a[1],config);
    },
    unsetHaveData : function(row,col){
        var config = {haveData:false};
        var a = arguments;
        if(a.length==1){
            var place = this.getPlaceByDay(a[0]);
            if(place!=null){
                this.changeBlock(place.row,place.col,config);
            }
        }
        else
            this.changeBlock(a[0],a[1],config);
    },
    
    reLoadDatePanel : function(){
        var _data = this.getDateList(this.year,this.month);
        this.dateList = [].concat(_data.dateList);
        this.flagList = [].concat(_data.flagList);
        _data=null;

        //-----------------------------------------------------------
        for(var i=0;i<this.dateList.length;i++){
            for(var j=0;j<7;j++){
                this.changeBlock(i,j,{
                    date        : this.dateList[i][j],
                    isThisMonth : this.flagList[i][j],
                    resetBgColor: true
                });
            }
        }
    },
    
    setDate : function(year,month){
        if(arguments.length==1){
            var tmp = arguments[0].split("-");
            year = tmp[0];
            month= parseInt(tmp[1],10);
        }
        this.year = (year==undefined)?sc.getYear():parseInt(year,10);
        this.month = (month==undefined)?sc.getMonth():parseInt(month,10);
        
        this.obj_year.setValue(this.year);
        this.obj_month.setValue(this.month);
        
        this.reLoadDatePanel();

        //-----------------------------------------------------------
        if(this.autoChange===true){
            this.searchClick.call('',this.year,this.month);
        }
    },
    
    searchClick : function(){
    },
    dateClick : function(){
    },
    //-----------------------------------------------------------    
    onSearchClick : function(){
        this.setDate(this.year,this.month);   
        if(this.autoChange!==true)
            this.searchClick.call('',this.year,this.month);
    },
    
    onYearSelect : function(){
        this.year = arguments[1].get('text');
        if(this.autoChange===true){
            this.setDate(this.year,this.month);
        }
    },
    
    onMonthSelect : function(){
        this.month = arguments[1].get('text');
        if(this.autoChange===true){
            this.setDate(this.year,this.month);
        }
    },
    onDateClick : function(e,field){
        var row = parseInt(field.id.split("_")[1],10);
        var col = parseInt(field.id.split("_")[2],10);
        
        if(this.isCurrentMonth(row,col)&&field.style.borderColor!='#dedede'){
            var tmpDate = this.year+'-'+((parseInt(this.month,10)<10)?"0"+this.month:""+this.month)+'-'+this.dateList[row][col];
            this.selectedDate = tmpDate;
            this.dateClick.call(e,tmpDate);
        }
    },
    
    isCurrentMonth:function(row,col){
        if(this.flagList)
            return (this.flagList[row][col]===1)?true:false;
        else 
            return false;
    },
    
    //-----------------------------------------------------------    
    createWidgetElement:function(){
        var containerDiv = this.getOCD();
        
        var tbarDiv = document.createElement( "DIV" );     //创建标题容器
        containerDiv.appendChild( tbarDiv );               //添加到包裹容器
        Sail.apply(tbarDiv.style,{border:"0 #ababab solid",left:0,top:0,height:21,cursor:"default",position:"absolute"});
        var tbarID = this.id+"_tbar";
        
        tbarDiv.innerHTML = "<table id='"+tbarID+"' style='cursor:hand' height=21 cellspacing=0>"
            +"<tr height=21><td class='tbar_lcorner' width=2></td><td width=4 class='tbar_back'></td>"
            +"<td class='tbar_app'  width=16></td><td width=4 class='tbar_back'></td>"
            +"<td height=21 class='tbar_back' style='padding-top:3'>"+this.title+"</td>"
            +"<td width=2 class='tbar_back'></td><td class='tbar_right' width=22></td></tr></table>";
        
        this.barDiv = tbarDiv;
        
        var tFormDiv = document.createElement( "DIV" );     //创建标题容器
        tFormDiv.id='yujunjie';
        
        containerDiv.appendChild( tFormDiv );               //添加到包裹容器
        Sail.apply(tFormDiv.style,{border:"0 #ababab solid",left:0,top:21,height:this.height-21,cursor:"default",position:"absolute"});

        this.el = new Ext.FormPanel({
            animCollapse:false,
            labelAlign: 'top',
            bodyStyle:'padding:5px',
            width: this.width,
            height:this.height-21,
            autoWidth: this.autoWidth,
            renderTo:tFormDiv,
            items: [{
                layout:'column',
                border:false
            }]
            
        });
        this.OCBC   = this.el.body.dom;

        //-----------------------------------------------------------------------------
        //【】
        //-----------------------------------------------------------------------------
        var _margLeft   = (this.margLeft==undefined)?10:this.margLeft;
        var _margRight  = (this.margRight==undefined)?10:this.margRight;
        var _spacing    = (this.blockSpace==undefined)?6:this.blockSpace;
        var _blockWidth = 30;
        var _beginYear  = (this.beginYear==undefined)?2008:this.beginYear;
        var _yearLength = (this.yearLength==undefined)?10:this.yearLength;
        
        //-----------------------------------------------------------------------------
        //【年度、月度 bar】
        //-----------------------------------------------------------------------------
        var barWidth = this.width-_margLeft-_margRight-_spacing;
        var width_year = 80; 
        var width_month= 60; 
        var yearTitleDiv  = document.createElement( "DIV" );    
        Sail.apply(yearTitleDiv.style,{
            left    : 10,
            top     : 15,
            width   : 40,
            height  : 25,
            position: "absolute",
            border  : "0px #808080 solid"
        });
        this.OCBC.appendChild(yearTitleDiv);         //添加到设计窗口
        yearTitleDiv.innerText = "年：";

        var yearDiv  = document.createElement( "DIV" );    
        Sail.apply(yearDiv.style,{
            left    : 36,
            top     : 10,
            width   : width_year,
            height  : 30,
            position: "absolute",
            border  : "0px #808080 solid"
        });
        this.OCBC.appendChild(yearDiv);         //添加到设计窗口
        
        this.yearArray = [];
        for(var i=0;i<_yearLength;i++)
            this.yearArray.push([_beginYear+i,_beginYear+i]);
            
        var store = new Ext.data.SimpleStore({fields:['text','code'],data :this.yearArray});
        var _config = {
            readOnly:true,
            mode: 'local',
            store: store,
            width : width_year,
            displayField:'text',
            name:'text',
            valueField:'code',
            forceSelection : true,
            typeAhead: true,
            triggerAction: 'all',
            selectOnFocus:true,
            value:'',
            renderTo: yearDiv    
        };    
        this.obj_year = new Ext.form.ComboBox(_config);
        this.obj_year.on('select',this.onYearSelect,this);
        
        //-----------------------------------------------------------
        var monthTitleDiv  = document.createElement( "DIV" );    
        Sail.apply(monthTitleDiv.style,{
            left    : 126,
            top     : 15,
            width   : 40,
            height  : 25,
            position: "absolute",
            border  : "0px #808080 solid"
        });
        this.OCBC.appendChild(monthTitleDiv);         //添加到设计窗口
        monthTitleDiv.innerText = "月：";

        var monthDiv  = document.createElement( "DIV" );    
        Sail.apply(monthDiv.style,{
            left    : 150,
            top     : 10,
            width   : width_month,
            height  : 30,
            position: "absolute",
            border  : "0px #808080 solid"
        });
        this.OCBC.appendChild(monthDiv);         //添加到设计窗口

        this.monthArray = [];
        for(var i=1;i<13;i++){
            var month = (i<10)?"0"+i:""+i;    
            this.monthArray.push([month,i]);
        }
        
        var store = new Ext.data.SimpleStore({fields:['text','code'],data :this.monthArray});
        var _config = {
            maxHeight:300,
            readOnly:true,
            mode: 'local',
            store: store,
            width : width_month,
            displayField:'text',
            name:'text',
            valueField:'code',
            forceSelection : true,
            typeAhead: true,
            triggerAction: 'all',
            selectOnFocus:true,
            value:'',
            renderTo: monthDiv    
        };    
        this.obj_month = new Ext.form.ComboBox(_config);
        this.obj_month.on('select',this.onMonthSelect,this);

        //-----------------------------------------------------------
        var searchDiv  = document.createElement( "DIV" );    
        Sail.apply(searchDiv.style,{
            left    : 226,
            top     : 10,
            width   : 40,
            height  : 25,
            position: "absolute",
            border  : "0px #808080 solid"
        });
        this.OCBC.appendChild(searchDiv);         //添加到设计窗口
        var config ={iconCls:'x-btn-left mySearch',cls: 'x-btn-icon',renderTo:searchDiv};
        this.obj_search = new Ext.Button(config);
        
        var theObj = this;
        this.obj_search.on('click',this.onSearchClick,this);

        //-----------------------------------------------------------------------------
        //【日历】
        //-----------------------------------------------------------------------------
        var _left = _margLeft;
        var _top  = 50;
        var weekText = ["日","一","二","三","四","五","六"];
        for(var j=0;j<7;j++){
            var weekDiv  = document.createElement( "DIV" );    
            var _color = (j==0||j==6)?"#FA6003":"#666666";
            Sail.apply(weekDiv.style,{
                left    : _left,
                top     : _top,
                width   : _blockWidth,
                height  : 20,
                position: "absolute",
                textAlign : 'center',
                color : _color
            });
            this.OCBC.appendChild(weekDiv);         //添加到设计窗口
            _left+=_blockWidth+_spacing;
            weekDiv.innerText=weekText[j];
        }

        //-----------------------------------------------------------------------------
        //-----------------------------------------------------------------------------
        this.createDatePanel();
    }
});



/**************************************************************************************************
* 对象： Sail.widget.ext.myForm
* 说明： 
*
**************************************************************************************************/
Sail.widget.ext.tabs = function(config){
    this.OCBC = null;
    this.barDiv = null;
    
    Sail.apply(this, config);
    Sail.widget.ext.superclass.constructor.call(this);
    this.tabWidth = 150;
}

Sail.extend(Sail.widget.ext.tabs,Sail.widget.ext,{
    
    createWidgetElement:function(){
        var containerDiv = this.getOCD();
        var theObj = this;

        var tabs = new Ext.TabPanel({
            renderTo:containerDiv,resizeTabs:true, enableTabScroll:true,
            tabWidth:this.tabWidth,width:this.width,height:this.height,autoWidth: this.autoWidth,plain:true,defaults: {autoScroll:true}
        });
        
        for(var i=0;i<this.tabCount;i++){
            tabs.add({
                id:this.id+'_'+i,title: this.tabTitles[i],iconCls: this.iconCls,closable:false
            }).show();
        }
        
        tabs.setHeight(this.height);
        
        //---------------------------------------------------------------------------------------------
        //【必须调用的接口方法】
        //---------------------------------------------------------------------------------------------
        this.entity = tabs;
    }
});

/**************************************************************************************************
* 对象： Sail.widget.ext.tree
* 说明： 
*
**************************************************************************************************/
Sail.widget.ext.tree = function(config){
    this.OCBC = null;
    
    Sail.apply(this, config);
    Sail.widget.ext.superclass.constructor.call(this);
}
Sail.extend(Sail.widget.ext.tree,Sail.widget.ext,{
    create_node:function(node_info, datamap, record, deep) {
    
        var id = node_info[datamap['id'] ? datamap['id'] : 'id']; 
        var text = node_info[datamap['text'] ? datamap['text'] : 'text']; 
        var params = {};
        
        for (k in node_info) {
            if(k=='children')
                params[k] = true;
            else
                params[k] = node_info[k];    
        }
        
        var checked = node_info[datamap['checked'] ? datamap['checked'] : 'checked'];
        if (checked == 'true')
        {
            checked = true;
        } 
        else if (checked == 'false') 
        {
            checked = false;
        } else {
            checked = '';
        }

        var leaf = node_info.children ? false : true;
    
        var tree_node = new Ext.tree.TreeNode({
            id: id,
            text: text,
            leaf: leaf,
            checked: checked,
            param: params,
            draggable: false
        });
        var theObj = this;
        if (!leaf) {
            if (node_info.children[record].length) {
                Ext.each(node_info.children[record], function(elN) {
                    tree_node.appendChild(theObj.create_node(elN, datamap, record));
                })        
            } else {
                tree_node.appendChild(theObj.create_node(node_info.children[record], datamap, record));
            }
        }
         
        return tree_node;
    },

    generate_tree:function(container, url, record_object, record_map, root_visiable) {
        var rv = root_visiable ? root_visiable : false;
        var root_node = new Ext.tree.TreeNode({
            id: 'zzzzzzzzzzzzzzzzzzzz',
            text: 'zzzzzzzzzzzzzzzzzzzz',
            leaf: false
        });    
        
        var tree = new Ext.tree.TreePanel({
            enableDD: false,
            autoScroll: true,
            animate: false,
            rootVisible: root_visiable,
            border: false,
            renderTo: container,
            root: root_node
        });    
    
        var p = new Ext.data.HttpProxy({
        	url: url,
        	method: 'POST'
        });
    
        p.on("loadexception", function(t, o, response, e) {
            if (e) throw e;
            Ext.Msg.alert('注意：', '读取数据出错!');
        });
        var theObj = this;
        p.load(null, {
            read: function(response) {
                var t = eval('(' + response.responseText + ')');
                
                if (t.dataset.response.success == 'false') {
                    Ext.Msg.alert('注意：', t.dataset.response.content);
                    return null;
                }
               
                /*
                ** 获取映射
                */
                if (record_map) {
                    var datamap = record_map;
                } else {
                    var maparray = t.dataset.datamap.replace(/\s/, '').split(',');
                    var datamap = {};
                    Ext.each(maparray, function(el) {
                        var key = el.split('=')[1];
                        var value = el.split('=')[0];
                        datamap[key] = value;
                    });                  
                }
                
                if (record_object) {
                    var record = record_object;//取得对象标志
                } else {
                    var record = t.dataset.objects;//取得对象标志
                }
            
                /*
                var maparray = t.dataset.datamap.replace(/\s/, '').split(',');
                var datamap = {};
                Ext.each(maparray, function(el) {
                    var key = el.split('=')[1];
                    var value = el.split('=')[0];
                    datamap[key] = value;
                });            
                
                var record = t.dataset.objects;//取得对象标志
                */

                //*
                if (t.dataset[record].length) {
                    Ext.each(t.dataset[record], function(elN) {
                        root_node.appendChild(theObj.create_node(elN, datamap, record));
                    })        
                } else {
                    root_node.appendChild(theObj.create_node(t.dataset[record], datamap, record));
                }
                //*/
                
                //root_node.appendChild(theObj.create_node(t.dataset[record], datamap, record));
                
                tree.expandAll();
            }
        }, function() {}, tree);  
        return tree;
    },
    reload : function(){
        this.el.destroy();
        
        var url = (arguments.length>0)?arguments[0]:this.url;
        //debugger;
        this.el = this.generate_tree(this.OCBC, url);
    },
    createWidgetElement:function(){
        var containerDiv = this.getOCD();
        
        //-----------------------------------------------------------
        //-----------------------------------------------------------
        var tbarDiv = document.createElement( "DIV" );     //创建标题容器
        containerDiv.appendChild( tbarDiv );               //添加到包裹容器
        Sail.apply(tbarDiv.style,{border:"0 #ababab solid",left:0,top:0,height:21,cursor:"default",position:"absolute"});
        
        tbarDiv.innerHTML = "<table style='cursor:hand' height=21 cellspacing=0>"
            +"<tr height=21><td class='tbar_lcorner' width=2></td><td width=4 class='tbar_back'></td>"
            +"<td class='tbar_app'  width=16></td><td width=4 class='tbar_back'></td>"
            +"<td height=21 class='tbar_back' style='padding-top:3'>"+this.title+"</td>"
            +"<td width=2 class='tbar_back'></td><td class='tbar_right' width=22></td></tr></table>";
        this.barDiv = tbarDiv;
        var tFormDiv = document.createElement( "DIV" );     //创建标题容器
        containerDiv.appendChild( tFormDiv );               //添加到包裹容器
        Sail.apply(tFormDiv.style,{border:"0 #ababab solid",left:0,top:21,height:this.height-21,cursor:"default",position:"absolute"});
        
        //-----------------------------------------------------------
        //-----------------------------------------------------------
        this.el = new Ext.FormPanel({
            animCollapse:false,
            labelAlign: 'top',
            bodyStyle:'padding:5px',
            width: this.width,
            height:this.height-21,
            autoWidth: this.autoWidth,
            autoScroll:true,
            renderTo:tFormDiv,
            items: [{
                layout:'column',
                border:false
            }]
            
        });

        //-----------------------------------------------------------
        //-----------------------------------------------------------
        this.OCBC   = this.el.body.dom;
        if(this.url!=undefined && this.url!="")
            this.el = this.generate_tree(this.OCBC, this.url);
    }
});

/**************************************************************************************************
* 对象： Sail.widget.ext.polyLine
* 说明： 折线图
*
**************************************************************************************************/
Sail.widget.ext.polyLine = function(config){
    this.OCBC = null;
    //this.scale = 100;
    this.legend = true;
    
    Sail.apply(this, config);
    Sail.widget.ext.superclass.constructor.call(this);
    
    this.lineGroup = [];
}
Sail.extend(Sail.widget.ext.polyLine,Sail.widget.ext,{
    getCoorInfo : function(maxValue){
        var robj = {maxValue:10,yCount:5};

        var digit = this.getDigit(maxValue)-1;
        var first  = Math.floor(maxValue/Math.pow(10,digit));
        var second = Math.floor(Math.round((maxValue-first*Math.pow(10,digit))/Math.pow(10,digit-1)));
        
        var _maxValue = first*Math.pow(10,digit);

        var _a = _maxValue/10;
        var _b = second*Math.pow(10,digit-1);
        var _c = Math.round(_b/_a);
        
        if(_c<5) {
            robj.maxValue = _maxValue+_a*_c;
            robj.yCount   = 10+_c;
        }
        else{
            robj.maxValue = (first+1)*Math.pow(10,digit);
            robj.yCount   = 10;
        }
        //debugger;
        
        
        return robj;
    },
    
    getMaxYCoordinate : function(maxValue){
        
        if(maxValue==0) return maxValue;
        
        var digit = this.getDigit(maxValue)-1;
        var robj = {maxValue:10,yCount:5};
        
        if(digit==0){
            robj.maxValue = (maxValue>5)?10:5;
            robj.yCount   = (maxValue>5)?10:5;
            return robj;
        }else if(digit==1){
            robj.maxValue = (maxValue>50)?100:50;
            robj.yCount   = (maxValue>50)?10:5;
            return robj;
        }
        else
            return this.getCoorInfo(maxValue);
        
    },
    getDigit: function(number){
        var _tmp = parseInt(number,10);
        return (""+_tmp).length;
    },
    increaseArray : function(dataArray){
        var len = dataArray.length;
        
        var returnArray = new Array(len);
        returnArray[0] = parseFloat(dataArray[0]);
        
        for(var i=1;i<len;i++){
            var count = 0;
            for(var j=0;j<=i;j++){
                count +=parseFloat(dataArray[j]);
            }
            returnArray[i] = count;
        }
        
        return returnArray;
    },
    
    clear : function(){
        this.lineGroup = [];
        
        if(this.legendDiv!=undefined)
            this.legendDiv.innerHTML="";
            
        this.vmlObj.hidePolyLine(true);
    },
    
    clear2: function(){
        if(this.legendDiv!=undefined)
            this.legendDiv.innerHTML="";
            
        this.vmlObj.hidePolyLine(true);
    },
    
    clearCoordinate : function(){
        if(this.legendDiv!=undefined)
            this.legendDiv.innerHTML="";
            
        this.vmlObj.hideCoordinate(true);
    },
    
    load : function(){
        var config = {};
        
        //-----------------------------------------------------------
        //处理入参
        //-----------------------------------------------------------
        if(arguments.length!=0){
            var a = arguments[0];
            if(typeof a =="object"){
                Ext.apply(this,a);
                config = a;
            }else{
                this.url = a;
            }
        }
        
        if(this.url==undefined || this.url=="") {
            Ext.Msg.alert("信息：","没有找到关于数据源的定义！无法获取数据！");
            return;
        }

        //-----------------------------------------------------------
        //this.clear();
        
        //-----------------------------------------------------------
        //-----------------------------------------------------------
        if(config.reader == undefined)      config.reader = this.reader;
        if(config.titleRender == undefined) config.titleRender = this.titleRender;
        
        var reader = config.reader;
        if(reader==undefined){
            Ext.Msg.alert("信息：","没有找到关于数据解析对象的定义！无法解析数据！");
            return;
        }
        
        reader.yCoordinate =(reader.yCoordinate instanceof Array)?reader.yCoordinate:[reader.yCoordinate];
                
        var theObj = this;
        var vmlObj = this.vmlObj;
        
        var _callback = function(flag,getData){
            if(reader.type=="JsonReader"){
                
                var lineData = sc.getDataObj2(getData,reader.root);
                
                if(lineData==null ||lineData==undefined) return;
                lineData = (lineData instanceof Array)?lineData:[lineData];
                
                theObj.clear2();
                //debugger;
                //---------------------------------------------------
                //画线的配置对象
                //---------------------------------------------------
                var lineConfig={
                    xCoordinate:[],
                    yCoordinate:[],
                    titles:[]
                };
                lineConfig.pointRadius = (config.pointRadius!=undefined)?config.pointRadius:3;
                lineConfig.lineSize    = (config.lineSize!=undefined)?config.lineSize:1;
                lineConfig.pointColor  = (config.pointColor!=undefined)?config.pointColor:"#FF6600";
                lineConfig.lineColor   = (config.lineColor!=undefined)?config.lineColor:"#FF6600";
                lineConfig.name        = (config.name!=undefined)?config.name:"&nbsp;"; 
                //---------------------------------------------------
                //从DATA中根据配置的字段，解析各个坐标值
                //---------------------------------------------------
                for(var i=0;i<lineData.length;i++){
                    var tmpObj = lineData[i];
                    
                    var _x =i+1;
                    if(reader.xConversion!=undefined && typeof reader.xConversion =="function"){
                        _x = reader.xConversion(tmpObj[reader.xCoordinate]);
                    }
                    
                    var _title = "（"+tmpObj[reader.xCoordinate]+"，"+tmpObj[reader.yCoordinate]+"）";
                    if(config.titleRender!=undefined && typeof config.titleRender == "function"){
                        _title = config.titleRender(tmpObj[reader.xCoordinate],tmpObj[reader.yCoordinate]);
                    }
                    
                    lineConfig.xCoordinate.push(_x);
                    lineConfig.yCoordinate.push(tmpObj[reader.yCoordinate]);
                    lineConfig.titles.push(_title);
                }
                
                //------------------------------------------------------------
                //如果Y轴数据是递增模式，则重计算Y坐标值和title
                //------------------------------------------------------------
                if(config.reader.yCoordinateMode!=="noIncrease"){
                    lineConfig.yCoordinate = theObj.increaseArray(lineConfig.yCoordinate);
                    
                    lineConfig.titles=[];
                    for(var i=0;i<lineData.length;i++){
                        var tmpObj = lineData[i];
                        var _title = "（"+tmpObj[reader.xCoordinate]+"，"+lineConfig.yCoordinate[i]+"）";
                        if(config.titleRender!=undefined && typeof config.titleRender == "function"){
                            var tmpValue = sc.formatNum(lineConfig.yCoordinate[i]);
                            _title = config.titleRender(tmpObj[reader.xCoordinate],tmpValue);
                        }
                        lineConfig.titles.push(_title);
                    }
                }
                
                //------------------------------------------------------------
                //根据实际数据计算Y坐标最大值，并均分Y轴刻度
                //------------------------------------------------------------
                var xCoordinateText = [],yCoordinateText = [];
                
                var maxValue = eval("Math.max("+lineConfig.yCoordinate.join(',')+")");
                var coordinateObj  = theObj.getMaxYCoordinate(maxValue);    //计算Y坐标轴最大值
                var maxYCoordinate = coordinateObj.maxValue;
                var configYCount   = coordinateObj.yCount;
                
                for(var i=0;i<configYCount;i++)                             //计算Y坐标轴刻度
                    yCoordinateText.push(maxYCoordinate/configYCount+i*(maxYCoordinate/configYCount));
                
                for(var i=0;i<31;i++) xCoordinateText.push(i+1);
                
                //------------------------------------------------------------
                //Y坐标轴和最大刻度记录在config中
                //------------------------------------------------------------
                lineConfig.yCoordinateText = yCoordinateText;
                lineConfig.maxYCoordinate  = maxYCoordinate;
                lineConfig.configYCount    = configYCount;
                
                //------------------------------------------------------------
                //判断是否有折线已经存在，并且最大Y轴刻度大于当前Y轴刻度
                //------------------------------------------------------------
                //debugger;
                var _index = -1;
                var _max = maxYCoordinate;
                for(var i =0 ;i<theObj.lineGroup.length;i++){
                    if(theObj.lineGroup[i].maxYCoordinate>_max){
                        _max = theObj.lineGroup[i].maxYCoordinate;
                        _index = i;
                    }
                }
                
                //------------------------------------------------------------
                //根据查询结果设置当前坐标系
                //1、如果存在Y轴刻度大于当前刻度
                //   取已存在坐标系为当前坐标系
                //2、如果没有(还需判断Y轴刻度数目)
                //   ????
                //------------------------------------------------------------
                if(_index!=-1){     
                    maxYCoordinate = theObj.lineGroup[_index].maxYCoordinate;
                    configYCount   = theObj.lineGroup[_index].configYCount;
                    yCoordinateText= [].concat(theObj.lineGroup[_index].yCoordinateText);
                    
                    //theObj.lastConfig.maxYCoordinate = maxYCoordinate;
                    //theObj.lastConfig.configYCount   = configYCount;
                    //theObj.lastConfig.yCoordinateText= [].concat(yCoordinateText);
                    
                }else{
                    /*if(theObj.lastConfig.maxYCoordinate==undefined){
                        theObj.lastConfig.maxYCoordinate = maxYCoordinate;
                        theObj.lastConfig.configYCount   = configYCount;
                        theObj.lastConfig.yCoordinateText= [].concat(yCoordinateText);
                    }*/
                    
                    //maxYCoordinate = theObj.lastConfig.maxYCoordinate;
                    //configYCount   = theObj.lastConfig.configYCount;
                    //yCoordinateText= [].concat(theObj.lastConfig.yCoordinateText);
                }
                
                //------------------------------------------------------------
                //------------------------------------------------------------
                vmlObj.configYPerValue = maxYCoordinate/configYCount;
                vmlObj.configYMinValue = vmlObj.configYPerValue; 
            	vmlObj.configXValue = xCoordinateText;          //X坐标轴刻度，从1号到31号
                vmlObj.configYValue = yCoordinateText;          //Y坐标轴刻度
                vmlObj.reInit();
                
                //------------------------------------------------------------
                //------------------------------------------------------------
                theObj.lineGroup.push(lineConfig);              //加入本次加载的折线
                for(var i=0;i<theObj.lineGroup.length;i++)      //重新渲染全部折线
                    theObj.drawLine(theObj.lineGroup[i]);

                //------------------------------------------------------------
                //加载图例交互部分
                //------------------------------------------------------------
                theObj.add2CheckList();
                
                //alert();
            }
        };
        
        sc.postData(this.url,{},_callback);
    },
    
    add2CheckList: function(listconfig){
        if(this.legendDiv==undefined) return;
        
        var html = "";
        html+="<table >";
        html+="<tr height=6><td colspan=2></td></tr>";
        html+="<tr><td colspan=3 style='font:normal 12px verdana;font-weight:bold;color:#15428B'>图例:</td></tr>";
        html+="<tr height=6><td colspan=2></td></tr>";
        
        for(var i=0;i<this.lineGroup.length;i++){
            var tmpId  = this.id+"_line_"+i;
            var _color = this.lineGroup[i].lineColor;
            var _name  = this.lineGroup[i].name;
            html+="<tr height=16><td width=20><input id='"+tmpId+"' type=checkbox checked></td>";
            html+="<td width=16 style='background-color:"+_color+"'>&nbsp;</td>";
            html+="<td nowrap style='font:normal 12px verdana;'>"+_name+"</td></tr>";
            html+="<tr height=6><td colspan=2></td></tr>";
        }
        html+="</table>";
        this.legendDiv.innerHTML = html;
        
        (function(){        
            for(var i=0;i<this.lineGroup.length;i++){
                Ext.get(this.id+"_line_"+i).on('click',function(e){
                    
                    var index = parseInt(e.target.id.replace(this.id+"_line_",""));
                    var check = e.target.checked;
                    
                    var line = this.vmlObj.lineObjs[index];
                    if(check){
                        line.style.display='';
                        var points = this.vmlObj.pointObjs[index];
                        for(var i=0;i<points.length;i++)
                            points[i].style.display='';
                    }else{
                        line.style.display='none';
                        var points = this.vmlObj.pointObjs[index];
                        for(var i=0;i<points.length;i++)
                            points[i].style.display='none';
                    }
                },this);
            }
        }).defer(50,this);
        
    },
        
    drawLine : function(lineConfig){

        lineConfig = (lineConfig==undefined)?{}:lineConfig;     //取得配置对象

        //--------------------------------------------------------------------------------
        var pointRadius = (lineConfig.pointRadius!=undefined)?lineConfig.pointRadius:3;         //点直径
    	var lineSize    = (lineConfig.lineSize!=undefined)?lineConfig.lineSize:1;               //线的大小
    	var pointColor  = (lineConfig.pointColor!=undefined)?lineConfig.pointColor:"#FF6600";   //点的颜色
    	var lineColor   = (lineConfig.lineColor!=undefined)?lineConfig.lineColor:"#FF6600";     //线的颜色
        
        var xCoordinate = (lineConfig.xCoordinate!=undefined)?lineConfig.xCoordinate:[];  //取得X坐标
        var yCoordinate = (lineConfig.yCoordinate!=undefined)?lineConfig.yCoordinate:[];  //取得Y坐标
        var titles      = (lineConfig.titles!=undefined)?lineConfig.titles:[];            //取得title
        
        //--------------------------------------------------------------------------------
    	this.vmlObj.setPointsProp(pointRadius,lineSize,pointColor,lineColor);   //设置圆点的属性
    	
        //--------------------------------------------------------------------------------
    	this.vmlObj.setPointsValue(xCoordinate,yCoordinate,titles);	            //画线
    	
    	return lineConfig;
    },
    
    createVMLObj : function(config){
        
        //-----------------------------------------------------------
        //-----------------------------------------------------------
        var gpWidth = this.width-4;
        if(config.legend===true)    {
            gpWidth-=(this.legendWidth==undefined)?120:this.legendWidth;
        }
        
        //-----------------------------------------------------------
        //-----------------------------------------------------------
    	//建立曲线对象
    	var vc = new VMLCurve(this.OCBC);
        vc.needOriginValue = false;
    	vc.gpWidth = gpWidth;
    	vc.gpHeight = this.height-35;
    	
    	vc.configXValue = [];       //X轴坐标值文本
        vc.configYValue = [];       //
        vc.configXHeight = 3;
        //vc.configXTextMode = "middleSpace"; 
        
    	//设置Y坐标轴
    	//vc.configYPerValue = (config.configYPerValue!=undefined)?config.configYPerValue:10000;
        //vc.configYMinValue = vc.configYPerValue; 
    	vc.init();
    	
    	return vc;        
    },    
    createWidgetElement:function(){
        var containerDiv = this.getOCD();
        
        //-----------------------------------------------------------
        //-----------------------------------------------------------
        if(this.showTitle===true){
            var tbarDiv = document.createElement( "DIV" );     //创建标题容器
            containerDiv.appendChild( tbarDiv );               //添加到包裹容器
            Sail.apply(tbarDiv.style,{border:"0 #ababab solid",left:0,top:0,height:21,cursor:"default",position:"absolute"});
            
            tbarDiv.innerHTML = "<table style='cursor:hand' height=21 cellspacing=0>"
                +"<tr height=21><td class='tbar_lcorner' width=2></td><td width=4 class='tbar_back'></td>"
                +"<td class='tbar_app'  width=16></td><td width=4 class='tbar_back'></td>"
                +"<td height=21 class='tbar_back' style='padding-top:3'>"+this.title+"</td>"
                +"<td width=2 class='tbar_back'></td><td class='tbar_right' width=22></td></tr></table>";
            this.barDiv = tbarDiv;
        }

        var formDiv = document.createElement( "DIV" );     //创建标题容器
        containerDiv.appendChild( formDiv );               //添加到包裹容器


        var formTop  = (this.showTitle===true)?21:0;
        var formBord = (this.border!=undefined)?this.border:"1 #99BBE8 solid";
        var formConfig = {
            left:0,
            top:formTop,
            width : this.width,
            height:this.height-21,
            cursor:"default",
            position:"absolute"
        };
        if(this.showBorder===true) formConfig.border = formBord;
        Sail.apply(formDiv.style,formConfig);

        //-----------------------------------------------------------
        //-----------------------------------------------------------
        this.legendText="线图";
        //if(this.legend!==true){
        if(this.legend===true){
            var legendDiv = document.createElement( "DIV" );        //创建标题容器
            containerDiv.appendChild(legendDiv);                    //添加到包裹容器

            var legendConfig = {
                left:this.width-((this.legendWidth==undefined)?120:this.legendWidth),
                top:formTop,
                width : (this.legendWidth==undefined)?120:this.legendWidth,
                height:this.height-21,
                cursor:"default",
                position:"absolute",
                border : "0px solid #ff0000"
            };
            Sail.apply(legendDiv.style,legendConfig);
            
            this.legendDiv = legendDiv;
            
        }
        
        
        
        //-----------------------------------------------------------
        //-----------------------------------------------------------
        this.OCBC   = formDiv;
        //this.configYCount = (this.configYCount!=undefined)?this.configYCount:100
        
        this.vmlObj = this.createVMLObj({
            //configYPerValue:(this.configYPerValue!=undefined)?this.configYPerValue:10000,
            //configYCount:this.configYCount
            legend : this.legend
        });

    }
    
});


/**************************************************************************************************
* 对象： Sail.widget.ext.histogram
* 说明： 柱状图
*
**************************************************************************************************/
Sail.widget.ext.histogram = function(config){
    this.OCBC = null;
    
    Sail.apply(this, config);
    Sail.widget.ext.superclass.constructor.call(this);
}

Sail.extend(Sail.widget.ext.histogram,Sail.widget.ext,{
    
    getMaxYCoordinate : function(maxValue){
        if(maxValue==0) return maxValue;

        var digit = this.getDigit(maxValue)-1;
        var robj = {maxValue:10,yCount:5};
        
        if(digit==0){
            robj.maxValue = (maxValue>5)?10:5;
            robj.yCount   = (maxValue>5)?10:5;
            return robj;
        }
        
        var tmpMax1 = maxValue/Math.pow(10,digit);
        var tmpMax2 = Math.round(tmpMax1);
        
        tmpMax2 = (tmpMax2>tmpMax1)?tmpMax2:tmpMax2+1;
        robj.maxValue = ((tmpMax2>5)?10:5)*Math.pow(10,digit);
        robj.yCount   = (tmpMax2>5)?10:5;

        return robj;
    },
    getNearNum : function(maxvalue,limit){
        //return (maxvalue>limit*0.5)?limit:limit/2;
        return (maxvalue>limit*0.5)?limit:this.getNearNum(maxvalue,limit*0.5);
    },
    
    getDigit: function(number){
        var _tmp = parseInt(number,10);
        return (""+_tmp).length;
    },

    load : function(){
        var config = {};
        
        //-----------------------------------------------------------
        //处理入参
        //-----------------------------------------------------------
        if(arguments.length!=0){
            var a = arguments[0];
            if(typeof a =="object"){
                Ext.apply(this,a);
                config = a;
            }else{
                this.url = a;
            }
        }
        
        if(this.url==undefined || this.url=="") {
            Ext.Msg.alert("信息：","没有找到关于数据源的定义！无法获取数据！");
            return;
        }

        //-----------------------------------------------------------
        this.clear();
        
        //-----------------------------------------------------------
        //-----------------------------------------------------------
        if(config.reader == undefined)      config.reader = this.reader;
        if(config.titleRender == undefined) config.titleRender = this.titleRender;
        
        var reader = config.reader;
        if(reader==undefined){
            Ext.Msg.alert("信息：","没有找到关于数据解析对象的定义！无法解析数据！");
            return;
        }
        
        reader.yCoordinate =(reader.yCoordinate instanceof Array)?reader.yCoordinate:[reader.yCoordinate];
                
        var theObj = this;
        var vmlObj = this.vmlObj;
        
        var _callback = function(flag,getData){
            if(reader.type=="JsonReader"){
                
                var lineData = sc.getDataObj2(getData,reader.root);
                
                if(lineData==null ||lineData==undefined) return;
                lineData = (lineData instanceof Array)?lineData:[lineData];
                
                if(reader.spliceFunc!=undefined && typeof(reader.spliceFunc)=='function'){
                    for(var i=lineData.length-1;i>=0;i--){
                        if(reader.spliceFunc(lineData[i]))
                            lineData.splice(i,1);
                    }
                }
                
                //------------------------------------------------------------
                //------------------------------------------------------------
                var xCoordinateText =[],yCoordinateText = [];
                var xValues = [],yValues = [],titles=[];
                var tmpYValue = [];
                
                //------------------------------------------------------------
                //------------------------------------------------------------
                //for(var i=0;i<reader.yCoordinate.length;i++) yValues.push([]);
                for(var i=0;i<lineData.length;i++){
                    xCoordinateText.push(lineData[i][reader.xCoordinate]);
                    xValues.push(i+1);
                    yValues.push([]);
                    titles.push([]);
                    
                    for(var j=0;j<reader.yCoordinate.length;j++){           //计算Y坐标轴最大值用临时数组
                        var tmpv = (lineData[i][reader.yCoordinate[j]]==undefined)?0:lineData[i][reader.yCoordinate[j]];
                        tmpYValue.push(tmpv);
                        yValues[i].push(tmpv);
                    
                        var _title = "（"+lineData[i][reader.xCoordinate]+"，"+tmpv+"）";
                        if(config.titleRender!=undefined && typeof config.titleRender == "function"){
                            _title = config.titleRender(lineData[i][reader.xCoordinate],tmpv,reader.yCoordinate[j]);
                        }
                        titles[i].push(_title);
                    }
                }

                //------------------------------------------------------------
                //------------------------------------------------------------
                var maxValue = eval("Math.max("+tmpYValue.join(',')+")");
                
                var coordinateObj  = theObj.getMaxYCoordinate(maxValue);    //计算Y坐标轴最大值
                var maxYCoordinate = coordinateObj.maxValue;
                var configYCount   = coordinateObj.yCount;
                //configYCount = config.configYCount;
                for(var i=0;i<configYCount;i++)                             //计算Y坐标轴刻度
                    yCoordinateText.push(maxYCoordinate/configYCount+i*(maxYCoordinate/configYCount));
                
                //------------------------------------------------------------
                //------------------------------------------------------------
                vmlObj.configYPerValue = maxYCoordinate/configYCount;
                vmlObj.configYMinValue = vmlObj.configYPerValue; 
            	vmlObj.configXValue = xCoordinateText;
                vmlObj.configYValue = yCoordinateText;
                vmlObj.reInit();
                
                //------------------------------------------------------------
                //------------------------------------------------------------
                //debugger;
                vmlObj.createHistograms(xValues,yValues,titles,['#99BBE8','#8EE663','#ababab']);	

                //debugger;
            }
        };
        
        sc.postData(this.url,{},_callback);
    },
    
    clear : function(){
        this.vmlObj.hideHistograms(true);
    },
    
    createVMLObj : function(config){
        
        //-----------------------------------------------------------
        //-----------------------------------------------------------
        var gpWidth = this.width-4;
        if(config.legend===true)    {
            gpWidth-=100;
        }
        
        //-----------------------------------------------------------
        //-----------------------------------------------------------
    	//建立曲线对象
    	var vc = new VMLCurve(this.OCBC);
        vc.needOriginValue = false;
    	vc.gpWidth = gpWidth;
    	vc.gpHeight = this.height-35;
    	
    	vc.configXValue = [];       //X轴坐标值文本
        vc.configYValue = [];       //
        vc.configXHeight = 3;
        vc.configXTextMode = "middleSpace"; 
        
    	//设置Y坐标轴
    	//vc.configYPerValue = (config.configYPerValue!=undefined)?config.configYPerValue:10000;
        //vc.configYMinValue = vc.configYPerValue; 
    	vc.init();
    	
    	return vc;        
    },
    
    createWidgetElement:function(){
        var containerDiv = this.getOCD();
        
        //-----------------------------------------------------------
        //-----------------------------------------------------------
        if(this.showTitle===true){
            var tbarDiv = document.createElement( "DIV" );     //创建标题容器
            containerDiv.appendChild( tbarDiv );               //添加到包裹容器
            Sail.apply(tbarDiv.style,{border:"0 #ababab solid",left:0,top:0,height:21,cursor:"default",position:"absolute"});
            
            tbarDiv.innerHTML = "<table style='cursor:hand' height=21 cellspacing=0>"
                +"<tr height=21><td class='tbar_lcorner' width=2></td><td width=4 class='tbar_back'></td>"
                +"<td class='tbar_app'  width=16></td><td width=4 class='tbar_back'></td>"
                +"<td height=21 class='tbar_back' style='padding-top:3'>"+this.title+"</td>"
                +"<td width=2 class='tbar_back'></td><td class='tbar_right' width=22></td></tr></table>";
            this.barDiv = tbarDiv;
        }

        var formDiv = document.createElement( "DIV" );     //创建标题容器
        containerDiv.appendChild( formDiv );               //添加到包裹容器


        var formTop  = (this.showTitle===true)?21:0;
        var formBord = (this.border!=undefined)?this.border:"1 #99BBE8 solid";
        var formConfig = {
            left:0,
            top:formTop,
            width : this.width,
            height:this.height-21,
            cursor:"default",
            position:"absolute"
        };
        if(this.showBorder===true) formConfig.border = formBord;
        Sail.apply(formDiv.style,formConfig);

        //-----------------------------------------------------------
        //-----------------------------------------------------------
        if(this.legend===true){
            var legendDiv = document.createElement( "DIV" );        //创建标题容器
            containerDiv.appendChild(legendDiv);                    //添加到包裹容器

            var legendConfig = {
                left:this.width-100,
                top:formTop,
                width : 100,
                height:this.height-21,
                cursor:"default",
                position:"absolute",
                border : "0px solid #ff0000"
            };
            Sail.apply(legendDiv.style,legendConfig);
            
            this.legendDiv = legendDiv;
            
            if(this.legendText!=undefined){
                
                var colorList = ['#758FB2','#6DB04C','#838383'];
                var html = "";
                html+="<table width=100%>";
                html+="<tr height=6><td colspan=2></td></tr>";
                html+="<tr><td colspan=2 style='font:normal 12px verdana;font-weight:bold;color:#15428B'>图例:</td></tr>";
                html+="<tr height=6><td colspan=2></td></tr>";
                
                for(var i=0;i<this.legendText.length;i++){
                    html+="<tr height=16><td width=24% height=16 style='background-color:"+colorList[i]+"'>&nbsp;</td><td>&nbsp;</td></tr>";
                    html+="<tr><td colspan=2 style='font:normal 12px verdana;'>"+this.legendText[i]+"</td></tr>";
                    html+="<tr height=6><td colspan=2></td></tr>";
                }
    
                html+="</table>";
                this.legendDiv.innerHTML = html;
            }
            
        }
        
        
        
        //-----------------------------------------------------------
        //-----------------------------------------------------------
        this.OCBC   = formDiv;
        //this.configYCount = (this.configYCount!=undefined)?this.configYCount:100
        
        this.vmlObj = this.createVMLObj({
            //configYPerValue:(this.configYPerValue!=undefined)?this.configYPerValue:10000,
            //configYCount:this.configYCount
            legend : this.legend
        });

    }

});

//createHistograms